| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
| 4 * (C) 2001 Dirk Mueller ( mueller@kde.org ) | 4 * (C) 2001 Dirk Mueller ( mueller@kde.org ) |
| 5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2013 Apple Inc. All r
ights reserved. | 5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2013 Apple Inc. All r
ights reserved. |
| 6 * Copyright (C) 2006 Andrew Wellington (proton@wiretapped.net) | 6 * Copyright (C) 2006 Andrew Wellington (proton@wiretapped.net) |
| 7 * | 7 * |
| 8 * This library is free software; you can redistribute it and/or | 8 * This library is free software; you can redistribute it and/or |
| 9 * modify it under the terms of the GNU Library General Public | 9 * modify it under the terms of the GNU Library General Public |
| 10 * License as published by the Free Software Foundation; either | 10 * License as published by the Free Software Foundation; either |
| (...skipping 955 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 966 { | 966 { |
| 967 if (is8Bit()) | 967 if (is8Bit()) |
| 968 return WTF::find(characters8(), m_length, matchFunction, start); | 968 return WTF::find(characters8(), m_length, matchFunction, start); |
| 969 return WTF::find(characters16(), m_length, matchFunction, start); | 969 return WTF::find(characters16(), m_length, matchFunction, start); |
| 970 } | 970 } |
| 971 | 971 |
| 972 size_t StringImpl::find(const LChar* matchString, unsigned index) | 972 size_t StringImpl::find(const LChar* matchString, unsigned index) |
| 973 { | 973 { |
| 974 // Check for null or empty string to match against | 974 // Check for null or empty string to match against |
| 975 if (!matchString) | 975 if (!matchString) |
| 976 return notFound; | 976 return kNotFound; |
| 977 size_t matchStringLength = strlen(reinterpret_cast<const char*>(matchString)
); | 977 size_t matchStringLength = strlen(reinterpret_cast<const char*>(matchString)
); |
| 978 RELEASE_ASSERT(matchStringLength <= numeric_limits<unsigned>::max()); | 978 RELEASE_ASSERT(matchStringLength <= numeric_limits<unsigned>::max()); |
| 979 unsigned matchLength = matchStringLength; | 979 unsigned matchLength = matchStringLength; |
| 980 if (!matchLength) | 980 if (!matchLength) |
| 981 return min(index, length()); | 981 return min(index, length()); |
| 982 | 982 |
| 983 // Optimization 1: fast case for strings of length 1. | 983 // Optimization 1: fast case for strings of length 1. |
| 984 if (matchLength == 1) | 984 if (matchLength == 1) |
| 985 return WTF::find(characters16(), length(), *matchString, index); | 985 return WTF::find(characters16(), length(), *matchString, index); |
| 986 | 986 |
| 987 // Check index & matchLength are in range. | 987 // Check index & matchLength are in range. |
| 988 if (index > length()) | 988 if (index > length()) |
| 989 return notFound; | 989 return kNotFound; |
| 990 unsigned searchLength = length() - index; | 990 unsigned searchLength = length() - index; |
| 991 if (matchLength > searchLength) | 991 if (matchLength > searchLength) |
| 992 return notFound; | 992 return kNotFound; |
| 993 // delta is the number of additional times to test; delta == 0 means test on
ly once. | 993 // delta is the number of additional times to test; delta == 0 means test on
ly once. |
| 994 unsigned delta = searchLength - matchLength; | 994 unsigned delta = searchLength - matchLength; |
| 995 | 995 |
| 996 const UChar* searchCharacters = characters16() + index; | 996 const UChar* searchCharacters = characters16() + index; |
| 997 | 997 |
| 998 // Optimization 2: keep a running hash of the strings, | 998 // Optimization 2: keep a running hash of the strings, |
| 999 // only call equal if the hashes match. | 999 // only call equal if the hashes match. |
| 1000 unsigned searchHash = 0; | 1000 unsigned searchHash = 0; |
| 1001 unsigned matchHash = 0; | 1001 unsigned matchHash = 0; |
| 1002 for (unsigned i = 0; i < matchLength; ++i) { | 1002 for (unsigned i = 0; i < matchLength; ++i) { |
| 1003 searchHash += searchCharacters[i]; | 1003 searchHash += searchCharacters[i]; |
| 1004 matchHash += matchString[i]; | 1004 matchHash += matchString[i]; |
| 1005 } | 1005 } |
| 1006 | 1006 |
| 1007 unsigned i = 0; | 1007 unsigned i = 0; |
| 1008 // keep looping until we match | 1008 // keep looping until we match |
| 1009 while (searchHash != matchHash || !equal(searchCharacters + i, matchString,
matchLength)) { | 1009 while (searchHash != matchHash || !equal(searchCharacters + i, matchString,
matchLength)) { |
| 1010 if (i == delta) | 1010 if (i == delta) |
| 1011 return notFound; | 1011 return kNotFound; |
| 1012 searchHash += searchCharacters[i + matchLength]; | 1012 searchHash += searchCharacters[i + matchLength]; |
| 1013 searchHash -= searchCharacters[i]; | 1013 searchHash -= searchCharacters[i]; |
| 1014 ++i; | 1014 ++i; |
| 1015 } | 1015 } |
| 1016 return index + i; | 1016 return index + i; |
| 1017 } | 1017 } |
| 1018 | 1018 |
| 1019 template<typename CharType> | 1019 template<typename CharType> |
| 1020 ALWAYS_INLINE size_t findIgnoringCaseInternal(const CharType* searchCharacters,
const LChar* matchString, unsigned index, unsigned searchLength, unsigned matchL
ength) | 1020 ALWAYS_INLINE size_t findIgnoringCaseInternal(const CharType* searchCharacters,
const LChar* matchString, unsigned index, unsigned searchLength, unsigned matchL
ength) |
| 1021 { | 1021 { |
| 1022 // delta is the number of additional times to test; delta == 0 means test on
ly once. | 1022 // delta is the number of additional times to test; delta == 0 means test on
ly once. |
| 1023 unsigned delta = searchLength - matchLength; | 1023 unsigned delta = searchLength - matchLength; |
| 1024 | 1024 |
| 1025 unsigned i = 0; | 1025 unsigned i = 0; |
| 1026 while (!equalIgnoringCase(searchCharacters + i, matchString, matchLength)) { | 1026 while (!equalIgnoringCase(searchCharacters + i, matchString, matchLength)) { |
| 1027 if (i == delta) | 1027 if (i == delta) |
| 1028 return notFound; | 1028 return kNotFound; |
| 1029 ++i; | 1029 ++i; |
| 1030 } | 1030 } |
| 1031 return index + i; | 1031 return index + i; |
| 1032 } | 1032 } |
| 1033 | 1033 |
| 1034 size_t StringImpl::findIgnoringCase(const LChar* matchString, unsigned index) | 1034 size_t StringImpl::findIgnoringCase(const LChar* matchString, unsigned index) |
| 1035 { | 1035 { |
| 1036 // Check for null or empty string to match against | 1036 // Check for null or empty string to match against |
| 1037 if (!matchString) | 1037 if (!matchString) |
| 1038 return notFound; | 1038 return kNotFound; |
| 1039 size_t matchStringLength = strlen(reinterpret_cast<const char*>(matchString)
); | 1039 size_t matchStringLength = strlen(reinterpret_cast<const char*>(matchString)
); |
| 1040 RELEASE_ASSERT(matchStringLength <= numeric_limits<unsigned>::max()); | 1040 RELEASE_ASSERT(matchStringLength <= numeric_limits<unsigned>::max()); |
| 1041 unsigned matchLength = matchStringLength; | 1041 unsigned matchLength = matchStringLength; |
| 1042 if (!matchLength) | 1042 if (!matchLength) |
| 1043 return min(index, length()); | 1043 return min(index, length()); |
| 1044 | 1044 |
| 1045 // Check index & matchLength are in range. | 1045 // Check index & matchLength are in range. |
| 1046 if (index > length()) | 1046 if (index > length()) |
| 1047 return notFound; | 1047 return kNotFound; |
| 1048 unsigned searchLength = length() - index; | 1048 unsigned searchLength = length() - index; |
| 1049 if (matchLength > searchLength) | 1049 if (matchLength > searchLength) |
| 1050 return notFound; | 1050 return kNotFound; |
| 1051 | 1051 |
| 1052 if (is8Bit()) | 1052 if (is8Bit()) |
| 1053 return findIgnoringCaseInternal(characters8() + index, matchString, inde
x, searchLength, matchLength); | 1053 return findIgnoringCaseInternal(characters8() + index, matchString, inde
x, searchLength, matchLength); |
| 1054 return findIgnoringCaseInternal(characters16() + index, matchString, index,
searchLength, matchLength); | 1054 return findIgnoringCaseInternal(characters16() + index, matchString, index,
searchLength, matchLength); |
| 1055 } | 1055 } |
| 1056 | 1056 |
| 1057 template <typename SearchCharacterType, typename MatchCharacterType> | 1057 template <typename SearchCharacterType, typename MatchCharacterType> |
| 1058 ALWAYS_INLINE static size_t findInternal(const SearchCharacterType* searchCharac
ters, const MatchCharacterType* matchCharacters, unsigned index, unsigned search
Length, unsigned matchLength) | 1058 ALWAYS_INLINE static size_t findInternal(const SearchCharacterType* searchCharac
ters, const MatchCharacterType* matchCharacters, unsigned index, unsigned search
Length, unsigned matchLength) |
| 1059 { | 1059 { |
| 1060 // Optimization: keep a running hash of the strings, | 1060 // Optimization: keep a running hash of the strings, |
| 1061 // only call equal() if the hashes match. | 1061 // only call equal() if the hashes match. |
| 1062 | 1062 |
| 1063 // delta is the number of additional times to test; delta == 0 means test on
ly once. | 1063 // delta is the number of additional times to test; delta == 0 means test on
ly once. |
| 1064 unsigned delta = searchLength - matchLength; | 1064 unsigned delta = searchLength - matchLength; |
| 1065 | 1065 |
| 1066 unsigned searchHash = 0; | 1066 unsigned searchHash = 0; |
| 1067 unsigned matchHash = 0; | 1067 unsigned matchHash = 0; |
| 1068 | 1068 |
| 1069 for (unsigned i = 0; i < matchLength; ++i) { | 1069 for (unsigned i = 0; i < matchLength; ++i) { |
| 1070 searchHash += searchCharacters[i]; | 1070 searchHash += searchCharacters[i]; |
| 1071 matchHash += matchCharacters[i]; | 1071 matchHash += matchCharacters[i]; |
| 1072 } | 1072 } |
| 1073 | 1073 |
| 1074 unsigned i = 0; | 1074 unsigned i = 0; |
| 1075 // keep looping until we match | 1075 // keep looping until we match |
| 1076 while (searchHash != matchHash || !equal(searchCharacters + i, matchCharacte
rs, matchLength)) { | 1076 while (searchHash != matchHash || !equal(searchCharacters + i, matchCharacte
rs, matchLength)) { |
| 1077 if (i == delta) | 1077 if (i == delta) |
| 1078 return notFound; | 1078 return kNotFound; |
| 1079 searchHash += searchCharacters[i + matchLength]; | 1079 searchHash += searchCharacters[i + matchLength]; |
| 1080 searchHash -= searchCharacters[i]; | 1080 searchHash -= searchCharacters[i]; |
| 1081 ++i; | 1081 ++i; |
| 1082 } | 1082 } |
| 1083 return index + i; | 1083 return index + i; |
| 1084 } | 1084 } |
| 1085 | 1085 |
| 1086 size_t StringImpl::find(StringImpl* matchString) | 1086 size_t StringImpl::find(StringImpl* matchString) |
| 1087 { | 1087 { |
| 1088 // Check for null string to match against | 1088 // Check for null string to match against |
| 1089 if (UNLIKELY(!matchString)) | 1089 if (UNLIKELY(!matchString)) |
| 1090 return notFound; | 1090 return kNotFound; |
| 1091 unsigned matchLength = matchString->length(); | 1091 unsigned matchLength = matchString->length(); |
| 1092 | 1092 |
| 1093 // Optimization 1: fast case for strings of length 1. | 1093 // Optimization 1: fast case for strings of length 1. |
| 1094 if (matchLength == 1) { | 1094 if (matchLength == 1) { |
| 1095 if (is8Bit()) { | 1095 if (is8Bit()) { |
| 1096 if (matchString->is8Bit()) | 1096 if (matchString->is8Bit()) |
| 1097 return WTF::find(characters8(), length(), matchString->character
s8()[0]); | 1097 return WTF::find(characters8(), length(), matchString->character
s8()[0]); |
| 1098 return WTF::find(characters8(), length(), matchString->characters16(
)[0]); | 1098 return WTF::find(characters8(), length(), matchString->characters16(
)[0]); |
| 1099 } | 1099 } |
| 1100 if (matchString->is8Bit()) | 1100 if (matchString->is8Bit()) |
| 1101 return WTF::find(characters16(), length(), matchString->characters8(
)[0]); | 1101 return WTF::find(characters16(), length(), matchString->characters8(
)[0]); |
| 1102 return WTF::find(characters16(), length(), matchString->characters16()[0
]); | 1102 return WTF::find(characters16(), length(), matchString->characters16()[0
]); |
| 1103 } | 1103 } |
| 1104 | 1104 |
| 1105 // Check matchLength is in range. | 1105 // Check matchLength is in range. |
| 1106 if (matchLength > length()) | 1106 if (matchLength > length()) |
| 1107 return notFound; | 1107 return kNotFound; |
| 1108 | 1108 |
| 1109 // Check for empty string to match against | 1109 // Check for empty string to match against |
| 1110 if (UNLIKELY(!matchLength)) | 1110 if (UNLIKELY(!matchLength)) |
| 1111 return 0; | 1111 return 0; |
| 1112 | 1112 |
| 1113 if (is8Bit()) { | 1113 if (is8Bit()) { |
| 1114 if (matchString->is8Bit()) | 1114 if (matchString->is8Bit()) |
| 1115 return findInternal(characters8(), matchString->characters8(), 0, le
ngth(), matchLength); | 1115 return findInternal(characters8(), matchString->characters8(), 0, le
ngth(), matchLength); |
| 1116 return findInternal(characters8(), matchString->characters16(), 0, lengt
h(), matchLength); | 1116 return findInternal(characters8(), matchString->characters16(), 0, lengt
h(), matchLength); |
| 1117 } | 1117 } |
| 1118 | 1118 |
| 1119 if (matchString->is8Bit()) | 1119 if (matchString->is8Bit()) |
| 1120 return findInternal(characters16(), matchString->characters8(), 0, lengt
h(), matchLength); | 1120 return findInternal(characters16(), matchString->characters8(), 0, lengt
h(), matchLength); |
| 1121 | 1121 |
| 1122 return findInternal(characters16(), matchString->characters16(), 0, length()
, matchLength); | 1122 return findInternal(characters16(), matchString->characters16(), 0, length()
, matchLength); |
| 1123 } | 1123 } |
| 1124 | 1124 |
| 1125 size_t StringImpl::find(StringImpl* matchString, unsigned index) | 1125 size_t StringImpl::find(StringImpl* matchString, unsigned index) |
| 1126 { | 1126 { |
| 1127 // Check for null or empty string to match against | 1127 // Check for null or empty string to match against |
| 1128 if (UNLIKELY(!matchString)) | 1128 if (UNLIKELY(!matchString)) |
| 1129 return notFound; | 1129 return kNotFound; |
| 1130 | 1130 |
| 1131 unsigned matchLength = matchString->length(); | 1131 unsigned matchLength = matchString->length(); |
| 1132 | 1132 |
| 1133 // Optimization 1: fast case for strings of length 1. | 1133 // Optimization 1: fast case for strings of length 1. |
| 1134 if (matchLength == 1) { | 1134 if (matchLength == 1) { |
| 1135 if (is8Bit()) | 1135 if (is8Bit()) |
| 1136 return WTF::find(characters8(), length(), (*matchString)[0], index); | 1136 return WTF::find(characters8(), length(), (*matchString)[0], index); |
| 1137 return WTF::find(characters16(), length(), (*matchString)[0], index); | 1137 return WTF::find(characters16(), length(), (*matchString)[0], index); |
| 1138 } | 1138 } |
| 1139 | 1139 |
| 1140 if (UNLIKELY(!matchLength)) | 1140 if (UNLIKELY(!matchLength)) |
| 1141 return min(index, length()); | 1141 return min(index, length()); |
| 1142 | 1142 |
| 1143 // Check index & matchLength are in range. | 1143 // Check index & matchLength are in range. |
| 1144 if (index > length()) | 1144 if (index > length()) |
| 1145 return notFound; | 1145 return kNotFound; |
| 1146 unsigned searchLength = length() - index; | 1146 unsigned searchLength = length() - index; |
| 1147 if (matchLength > searchLength) | 1147 if (matchLength > searchLength) |
| 1148 return notFound; | 1148 return kNotFound; |
| 1149 | 1149 |
| 1150 if (is8Bit()) { | 1150 if (is8Bit()) { |
| 1151 if (matchString->is8Bit()) | 1151 if (matchString->is8Bit()) |
| 1152 return findInternal(characters8() + index, matchString->characters8(
), index, searchLength, matchLength); | 1152 return findInternal(characters8() + index, matchString->characters8(
), index, searchLength, matchLength); |
| 1153 return findInternal(characters8() + index, matchString->characters16(),
index, searchLength, matchLength); | 1153 return findInternal(characters8() + index, matchString->characters16(),
index, searchLength, matchLength); |
| 1154 } | 1154 } |
| 1155 | 1155 |
| 1156 if (matchString->is8Bit()) | 1156 if (matchString->is8Bit()) |
| 1157 return findInternal(characters16() + index, matchString->characters8(),
index, searchLength, matchLength); | 1157 return findInternal(characters16() + index, matchString->characters8(),
index, searchLength, matchLength); |
| 1158 | 1158 |
| 1159 return findInternal(characters16() + index, matchString->characters16(), ind
ex, searchLength, matchLength); | 1159 return findInternal(characters16() + index, matchString->characters16(), ind
ex, searchLength, matchLength); |
| 1160 } | 1160 } |
| 1161 | 1161 |
| 1162 template <typename SearchCharacterType, typename MatchCharacterType> | 1162 template <typename SearchCharacterType, typename MatchCharacterType> |
| 1163 ALWAYS_INLINE static size_t findIgnoringCaseInner(const SearchCharacterType* sea
rchCharacters, const MatchCharacterType* matchCharacters, unsigned index, unsign
ed searchLength, unsigned matchLength) | 1163 ALWAYS_INLINE static size_t findIgnoringCaseInner(const SearchCharacterType* sea
rchCharacters, const MatchCharacterType* matchCharacters, unsigned index, unsign
ed searchLength, unsigned matchLength) |
| 1164 { | 1164 { |
| 1165 // delta is the number of additional times to test; delta == 0 means test on
ly once. | 1165 // delta is the number of additional times to test; delta == 0 means test on
ly once. |
| 1166 unsigned delta = searchLength - matchLength; | 1166 unsigned delta = searchLength - matchLength; |
| 1167 | 1167 |
| 1168 unsigned i = 0; | 1168 unsigned i = 0; |
| 1169 // keep looping until we match | 1169 // keep looping until we match |
| 1170 while (!equalIgnoringCase(searchCharacters + i, matchCharacters, matchLength
)) { | 1170 while (!equalIgnoringCase(searchCharacters + i, matchCharacters, matchLength
)) { |
| 1171 if (i == delta) | 1171 if (i == delta) |
| 1172 return notFound; | 1172 return kNotFound; |
| 1173 ++i; | 1173 ++i; |
| 1174 } | 1174 } |
| 1175 return index + i; | 1175 return index + i; |
| 1176 } | 1176 } |
| 1177 | 1177 |
| 1178 size_t StringImpl::findIgnoringCase(StringImpl* matchString, unsigned index) | 1178 size_t StringImpl::findIgnoringCase(StringImpl* matchString, unsigned index) |
| 1179 { | 1179 { |
| 1180 // Check for null or empty string to match against | 1180 // Check for null or empty string to match against |
| 1181 if (!matchString) | 1181 if (!matchString) |
| 1182 return notFound; | 1182 return kNotFound; |
| 1183 unsigned matchLength = matchString->length(); | 1183 unsigned matchLength = matchString->length(); |
| 1184 if (!matchLength) | 1184 if (!matchLength) |
| 1185 return min(index, length()); | 1185 return min(index, length()); |
| 1186 | 1186 |
| 1187 // Check index & matchLength are in range. | 1187 // Check index & matchLength are in range. |
| 1188 if (index > length()) | 1188 if (index > length()) |
| 1189 return notFound; | 1189 return kNotFound; |
| 1190 unsigned searchLength = length() - index; | 1190 unsigned searchLength = length() - index; |
| 1191 if (matchLength > searchLength) | 1191 if (matchLength > searchLength) |
| 1192 return notFound; | 1192 return kNotFound; |
| 1193 | 1193 |
| 1194 if (is8Bit()) { | 1194 if (is8Bit()) { |
| 1195 if (matchString->is8Bit()) | 1195 if (matchString->is8Bit()) |
| 1196 return findIgnoringCaseInner(characters8() + index, matchString->cha
racters8(), index, searchLength, matchLength); | 1196 return findIgnoringCaseInner(characters8() + index, matchString->cha
racters8(), index, searchLength, matchLength); |
| 1197 return findIgnoringCaseInner(characters8() + index, matchString->charact
ers16(), index, searchLength, matchLength); | 1197 return findIgnoringCaseInner(characters8() + index, matchString->charact
ers16(), index, searchLength, matchLength); |
| 1198 } | 1198 } |
| 1199 | 1199 |
| 1200 if (matchString->is8Bit()) | 1200 if (matchString->is8Bit()) |
| 1201 return findIgnoringCaseInner(characters16() + index, matchString->charac
ters8(), index, searchLength, matchLength); | 1201 return findIgnoringCaseInner(characters16() + index, matchString->charac
ters8(), index, searchLength, matchLength); |
| 1202 | 1202 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1242 unsigned searchHash = 0; | 1242 unsigned searchHash = 0; |
| 1243 unsigned matchHash = 0; | 1243 unsigned matchHash = 0; |
| 1244 for (unsigned i = 0; i < matchLength; ++i) { | 1244 for (unsigned i = 0; i < matchLength; ++i) { |
| 1245 searchHash += searchCharacters[delta + i]; | 1245 searchHash += searchCharacters[delta + i]; |
| 1246 matchHash += matchCharacters[i]; | 1246 matchHash += matchCharacters[i]; |
| 1247 } | 1247 } |
| 1248 | 1248 |
| 1249 // keep looping until we match | 1249 // keep looping until we match |
| 1250 while (searchHash != matchHash || !equal(searchCharacters + delta, matchChar
acters, matchLength)) { | 1250 while (searchHash != matchHash || !equal(searchCharacters + delta, matchChar
acters, matchLength)) { |
| 1251 if (!delta) | 1251 if (!delta) |
| 1252 return notFound; | 1252 return kNotFound; |
| 1253 --delta; | 1253 --delta; |
| 1254 searchHash -= searchCharacters[delta + matchLength]; | 1254 searchHash -= searchCharacters[delta + matchLength]; |
| 1255 searchHash += searchCharacters[delta]; | 1255 searchHash += searchCharacters[delta]; |
| 1256 } | 1256 } |
| 1257 return delta; | 1257 return delta; |
| 1258 } | 1258 } |
| 1259 | 1259 |
| 1260 size_t StringImpl::reverseFind(StringImpl* matchString, unsigned index) | 1260 size_t StringImpl::reverseFind(StringImpl* matchString, unsigned index) |
| 1261 { | 1261 { |
| 1262 // Check for null or empty string to match against | 1262 // Check for null or empty string to match against |
| 1263 if (!matchString) | 1263 if (!matchString) |
| 1264 return notFound; | 1264 return kNotFound; |
| 1265 unsigned matchLength = matchString->length(); | 1265 unsigned matchLength = matchString->length(); |
| 1266 unsigned ourLength = length(); | 1266 unsigned ourLength = length(); |
| 1267 if (!matchLength) | 1267 if (!matchLength) |
| 1268 return min(index, ourLength); | 1268 return min(index, ourLength); |
| 1269 | 1269 |
| 1270 // Optimization 1: fast case for strings of length 1. | 1270 // Optimization 1: fast case for strings of length 1. |
| 1271 if (matchLength == 1) { | 1271 if (matchLength == 1) { |
| 1272 if (is8Bit()) | 1272 if (is8Bit()) |
| 1273 return WTF::reverseFind(characters8(), ourLength, (*matchString)[0],
index); | 1273 return WTF::reverseFind(characters8(), ourLength, (*matchString)[0],
index); |
| 1274 return WTF::reverseFind(characters16(), ourLength, (*matchString)[0], in
dex); | 1274 return WTF::reverseFind(characters16(), ourLength, (*matchString)[0], in
dex); |
| 1275 } | 1275 } |
| 1276 | 1276 |
| 1277 // Check index & matchLength are in range. | 1277 // Check index & matchLength are in range. |
| 1278 if (matchLength > ourLength) | 1278 if (matchLength > ourLength) |
| 1279 return notFound; | 1279 return kNotFound; |
| 1280 | 1280 |
| 1281 if (is8Bit()) { | 1281 if (is8Bit()) { |
| 1282 if (matchString->is8Bit()) | 1282 if (matchString->is8Bit()) |
| 1283 return reverseFindInner(characters8(), matchString->characters8(), i
ndex, ourLength, matchLength); | 1283 return reverseFindInner(characters8(), matchString->characters8(), i
ndex, ourLength, matchLength); |
| 1284 return reverseFindInner(characters8(), matchString->characters16(), inde
x, ourLength, matchLength); | 1284 return reverseFindInner(characters8(), matchString->characters16(), inde
x, ourLength, matchLength); |
| 1285 } | 1285 } |
| 1286 | 1286 |
| 1287 if (matchString->is8Bit()) | 1287 if (matchString->is8Bit()) |
| 1288 return reverseFindInner(characters16(), matchString->characters8(), inde
x, ourLength, matchLength); | 1288 return reverseFindInner(characters16(), matchString->characters8(), inde
x, ourLength, matchLength); |
| 1289 | 1289 |
| 1290 return reverseFindInner(characters16(), matchString->characters16(), index,
ourLength, matchLength); | 1290 return reverseFindInner(characters16(), matchString->characters16(), index,
ourLength, matchLength); |
| 1291 } | 1291 } |
| 1292 | 1292 |
| 1293 template <typename SearchCharacterType, typename MatchCharacterType> | 1293 template <typename SearchCharacterType, typename MatchCharacterType> |
| 1294 ALWAYS_INLINE static size_t reverseFindIgnoringCaseInner(const SearchCharacterTy
pe* searchCharacters, const MatchCharacterType* matchCharacters, unsigned index,
unsigned length, unsigned matchLength) | 1294 ALWAYS_INLINE static size_t reverseFindIgnoringCaseInner(const SearchCharacterTy
pe* searchCharacters, const MatchCharacterType* matchCharacters, unsigned index,
unsigned length, unsigned matchLength) |
| 1295 { | 1295 { |
| 1296 // delta is the number of additional times to test; delta == 0 means test on
ly once. | 1296 // delta is the number of additional times to test; delta == 0 means test on
ly once. |
| 1297 unsigned delta = min(index, length - matchLength); | 1297 unsigned delta = min(index, length - matchLength); |
| 1298 | 1298 |
| 1299 // keep looping until we match | 1299 // keep looping until we match |
| 1300 while (!equalIgnoringCase(searchCharacters + delta, matchCharacters, matchLe
ngth)) { | 1300 while (!equalIgnoringCase(searchCharacters + delta, matchCharacters, matchLe
ngth)) { |
| 1301 if (!delta) | 1301 if (!delta) |
| 1302 return notFound; | 1302 return kNotFound; |
| 1303 --delta; | 1303 --delta; |
| 1304 } | 1304 } |
| 1305 return delta; | 1305 return delta; |
| 1306 } | 1306 } |
| 1307 | 1307 |
| 1308 size_t StringImpl::reverseFindIgnoringCase(StringImpl* matchString, unsigned ind
ex) | 1308 size_t StringImpl::reverseFindIgnoringCase(StringImpl* matchString, unsigned ind
ex) |
| 1309 { | 1309 { |
| 1310 // Check for null or empty string to match against | 1310 // Check for null or empty string to match against |
| 1311 if (!matchString) | 1311 if (!matchString) |
| 1312 return notFound; | 1312 return kNotFound; |
| 1313 unsigned matchLength = matchString->length(); | 1313 unsigned matchLength = matchString->length(); |
| 1314 unsigned ourLength = length(); | 1314 unsigned ourLength = length(); |
| 1315 if (!matchLength) | 1315 if (!matchLength) |
| 1316 return min(index, ourLength); | 1316 return min(index, ourLength); |
| 1317 | 1317 |
| 1318 // Check index & matchLength are in range. | 1318 // Check index & matchLength are in range. |
| 1319 if (matchLength > ourLength) | 1319 if (matchLength > ourLength) |
| 1320 return notFound; | 1320 return kNotFound; |
| 1321 | 1321 |
| 1322 if (is8Bit()) { | 1322 if (is8Bit()) { |
| 1323 if (matchString->is8Bit()) | 1323 if (matchString->is8Bit()) |
| 1324 return reverseFindIgnoringCaseInner(characters8(), matchString->char
acters8(), index, ourLength, matchLength); | 1324 return reverseFindIgnoringCaseInner(characters8(), matchString->char
acters8(), index, ourLength, matchLength); |
| 1325 return reverseFindIgnoringCaseInner(characters8(), matchString->characte
rs16(), index, ourLength, matchLength); | 1325 return reverseFindIgnoringCaseInner(characters8(), matchString->characte
rs16(), index, ourLength, matchLength); |
| 1326 } | 1326 } |
| 1327 | 1327 |
| 1328 if (matchString->is8Bit()) | 1328 if (matchString->is8Bit()) |
| 1329 return reverseFindIgnoringCaseInner(characters16(), matchString->charact
ers8(), index, ourLength, matchLength); | 1329 return reverseFindIgnoringCaseInner(characters16(), matchString->charact
ers8(), index, ourLength, matchLength); |
| 1330 | 1330 |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1503 } | 1503 } |
| 1504 | 1504 |
| 1505 PassRefPtr<StringImpl> StringImpl::replace(UChar pattern, const LChar* replaceme
nt, unsigned repStrLength) | 1505 PassRefPtr<StringImpl> StringImpl::replace(UChar pattern, const LChar* replaceme
nt, unsigned repStrLength) |
| 1506 { | 1506 { |
| 1507 ASSERT(replacement); | 1507 ASSERT(replacement); |
| 1508 | 1508 |
| 1509 size_t srcSegmentStart = 0; | 1509 size_t srcSegmentStart = 0; |
| 1510 unsigned matchCount = 0; | 1510 unsigned matchCount = 0; |
| 1511 | 1511 |
| 1512 // Count the matches. | 1512 // Count the matches. |
| 1513 while ((srcSegmentStart = find(pattern, srcSegmentStart)) != notFound) { | 1513 while ((srcSegmentStart = find(pattern, srcSegmentStart)) != kNotFound) { |
| 1514 ++matchCount; | 1514 ++matchCount; |
| 1515 ++srcSegmentStart; | 1515 ++srcSegmentStart; |
| 1516 } | 1516 } |
| 1517 | 1517 |
| 1518 // If we have 0 matches then we don't have to do any more work. | 1518 // If we have 0 matches then we don't have to do any more work. |
| 1519 if (!matchCount) | 1519 if (!matchCount) |
| 1520 return this; | 1520 return this; |
| 1521 | 1521 |
| 1522 RELEASE_ASSERT(!repStrLength || matchCount <= numeric_limits<unsigned>::max(
) / repStrLength); | 1522 RELEASE_ASSERT(!repStrLength || matchCount <= numeric_limits<unsigned>::max(
) / repStrLength); |
| 1523 | 1523 |
| 1524 unsigned replaceSize = matchCount * repStrLength; | 1524 unsigned replaceSize = matchCount * repStrLength; |
| 1525 unsigned newSize = m_length - matchCount; | 1525 unsigned newSize = m_length - matchCount; |
| 1526 RELEASE_ASSERT(newSize < (numeric_limits<unsigned>::max() - replaceSize)); | 1526 RELEASE_ASSERT(newSize < (numeric_limits<unsigned>::max() - replaceSize)); |
| 1527 | 1527 |
| 1528 newSize += replaceSize; | 1528 newSize += replaceSize; |
| 1529 | 1529 |
| 1530 // Construct the new data. | 1530 // Construct the new data. |
| 1531 size_t srcSegmentEnd; | 1531 size_t srcSegmentEnd; |
| 1532 unsigned srcSegmentLength; | 1532 unsigned srcSegmentLength; |
| 1533 srcSegmentStart = 0; | 1533 srcSegmentStart = 0; |
| 1534 unsigned dstOffset = 0; | 1534 unsigned dstOffset = 0; |
| 1535 | 1535 |
| 1536 if (is8Bit()) { | 1536 if (is8Bit()) { |
| 1537 LChar* data; | 1537 LChar* data; |
| 1538 RefPtr<StringImpl> newImpl = createUninitialized(newSize, data); | 1538 RefPtr<StringImpl> newImpl = createUninitialized(newSize, data); |
| 1539 | 1539 |
| 1540 while ((srcSegmentEnd = find(pattern, srcSegmentStart)) != notFound) { | 1540 while ((srcSegmentEnd = find(pattern, srcSegmentStart)) != kNotFound) { |
| 1541 srcSegmentLength = srcSegmentEnd - srcSegmentStart; | 1541 srcSegmentLength = srcSegmentEnd - srcSegmentStart; |
| 1542 memcpy(data + dstOffset, characters8() + srcSegmentStart, srcSegment
Length * sizeof(LChar)); | 1542 memcpy(data + dstOffset, characters8() + srcSegmentStart, srcSegment
Length * sizeof(LChar)); |
| 1543 dstOffset += srcSegmentLength; | 1543 dstOffset += srcSegmentLength; |
| 1544 memcpy(data + dstOffset, replacement, repStrLength * sizeof(LChar)); | 1544 memcpy(data + dstOffset, replacement, repStrLength * sizeof(LChar)); |
| 1545 dstOffset += repStrLength; | 1545 dstOffset += repStrLength; |
| 1546 srcSegmentStart = srcSegmentEnd + 1; | 1546 srcSegmentStart = srcSegmentEnd + 1; |
| 1547 } | 1547 } |
| 1548 | 1548 |
| 1549 srcSegmentLength = m_length - srcSegmentStart; | 1549 srcSegmentLength = m_length - srcSegmentStart; |
| 1550 memcpy(data + dstOffset, characters8() + srcSegmentStart, srcSegmentLeng
th * sizeof(LChar)); | 1550 memcpy(data + dstOffset, characters8() + srcSegmentStart, srcSegmentLeng
th * sizeof(LChar)); |
| 1551 | 1551 |
| 1552 ASSERT(dstOffset + srcSegmentLength == newImpl->length()); | 1552 ASSERT(dstOffset + srcSegmentLength == newImpl->length()); |
| 1553 | 1553 |
| 1554 return newImpl.release(); | 1554 return newImpl.release(); |
| 1555 } | 1555 } |
| 1556 | 1556 |
| 1557 UChar* data; | 1557 UChar* data; |
| 1558 RefPtr<StringImpl> newImpl = createUninitialized(newSize, data); | 1558 RefPtr<StringImpl> newImpl = createUninitialized(newSize, data); |
| 1559 | 1559 |
| 1560 while ((srcSegmentEnd = find(pattern, srcSegmentStart)) != notFound) { | 1560 while ((srcSegmentEnd = find(pattern, srcSegmentStart)) != kNotFound) { |
| 1561 srcSegmentLength = srcSegmentEnd - srcSegmentStart; | 1561 srcSegmentLength = srcSegmentEnd - srcSegmentStart; |
| 1562 memcpy(data + dstOffset, characters16() + srcSegmentStart, srcSegmentLen
gth * sizeof(UChar)); | 1562 memcpy(data + dstOffset, characters16() + srcSegmentStart, srcSegmentLen
gth * sizeof(UChar)); |
| 1563 | 1563 |
| 1564 dstOffset += srcSegmentLength; | 1564 dstOffset += srcSegmentLength; |
| 1565 for (unsigned i = 0; i < repStrLength; ++i) | 1565 for (unsigned i = 0; i < repStrLength; ++i) |
| 1566 data[i + dstOffset] = replacement[i]; | 1566 data[i + dstOffset] = replacement[i]; |
| 1567 | 1567 |
| 1568 dstOffset += repStrLength; | 1568 dstOffset += repStrLength; |
| 1569 srcSegmentStart = srcSegmentEnd + 1; | 1569 srcSegmentStart = srcSegmentEnd + 1; |
| 1570 } | 1570 } |
| 1571 | 1571 |
| 1572 srcSegmentLength = m_length - srcSegmentStart; | 1572 srcSegmentLength = m_length - srcSegmentStart; |
| 1573 memcpy(data + dstOffset, characters16() + srcSegmentStart, srcSegmentLength
* sizeof(UChar)); | 1573 memcpy(data + dstOffset, characters16() + srcSegmentStart, srcSegmentLength
* sizeof(UChar)); |
| 1574 | 1574 |
| 1575 ASSERT(dstOffset + srcSegmentLength == newImpl->length()); | 1575 ASSERT(dstOffset + srcSegmentLength == newImpl->length()); |
| 1576 | 1576 |
| 1577 return newImpl.release(); | 1577 return newImpl.release(); |
| 1578 } | 1578 } |
| 1579 | 1579 |
| 1580 PassRefPtr<StringImpl> StringImpl::replace(UChar pattern, const UChar* replaceme
nt, unsigned repStrLength) | 1580 PassRefPtr<StringImpl> StringImpl::replace(UChar pattern, const UChar* replaceme
nt, unsigned repStrLength) |
| 1581 { | 1581 { |
| 1582 ASSERT(replacement); | 1582 ASSERT(replacement); |
| 1583 | 1583 |
| 1584 size_t srcSegmentStart = 0; | 1584 size_t srcSegmentStart = 0; |
| 1585 unsigned matchCount = 0; | 1585 unsigned matchCount = 0; |
| 1586 | 1586 |
| 1587 // Count the matches. | 1587 // Count the matches. |
| 1588 while ((srcSegmentStart = find(pattern, srcSegmentStart)) != notFound) { | 1588 while ((srcSegmentStart = find(pattern, srcSegmentStart)) != kNotFound) { |
| 1589 ++matchCount; | 1589 ++matchCount; |
| 1590 ++srcSegmentStart; | 1590 ++srcSegmentStart; |
| 1591 } | 1591 } |
| 1592 | 1592 |
| 1593 // If we have 0 matches then we don't have to do any more work. | 1593 // If we have 0 matches then we don't have to do any more work. |
| 1594 if (!matchCount) | 1594 if (!matchCount) |
| 1595 return this; | 1595 return this; |
| 1596 | 1596 |
| 1597 RELEASE_ASSERT(!repStrLength || matchCount <= numeric_limits<unsigned>::max(
) / repStrLength); | 1597 RELEASE_ASSERT(!repStrLength || matchCount <= numeric_limits<unsigned>::max(
) / repStrLength); |
| 1598 | 1598 |
| 1599 unsigned replaceSize = matchCount * repStrLength; | 1599 unsigned replaceSize = matchCount * repStrLength; |
| 1600 unsigned newSize = m_length - matchCount; | 1600 unsigned newSize = m_length - matchCount; |
| 1601 RELEASE_ASSERT(newSize < (numeric_limits<unsigned>::max() - replaceSize)); | 1601 RELEASE_ASSERT(newSize < (numeric_limits<unsigned>::max() - replaceSize)); |
| 1602 | 1602 |
| 1603 newSize += replaceSize; | 1603 newSize += replaceSize; |
| 1604 | 1604 |
| 1605 // Construct the new data. | 1605 // Construct the new data. |
| 1606 size_t srcSegmentEnd; | 1606 size_t srcSegmentEnd; |
| 1607 unsigned srcSegmentLength; | 1607 unsigned srcSegmentLength; |
| 1608 srcSegmentStart = 0; | 1608 srcSegmentStart = 0; |
| 1609 unsigned dstOffset = 0; | 1609 unsigned dstOffset = 0; |
| 1610 | 1610 |
| 1611 if (is8Bit()) { | 1611 if (is8Bit()) { |
| 1612 UChar* data; | 1612 UChar* data; |
| 1613 RefPtr<StringImpl> newImpl = createUninitialized(newSize, data); | 1613 RefPtr<StringImpl> newImpl = createUninitialized(newSize, data); |
| 1614 | 1614 |
| 1615 while ((srcSegmentEnd = find(pattern, srcSegmentStart)) != notFound) { | 1615 while ((srcSegmentEnd = find(pattern, srcSegmentStart)) != kNotFound) { |
| 1616 srcSegmentLength = srcSegmentEnd - srcSegmentStart; | 1616 srcSegmentLength = srcSegmentEnd - srcSegmentStart; |
| 1617 for (unsigned i = 0; i < srcSegmentLength; ++i) | 1617 for (unsigned i = 0; i < srcSegmentLength; ++i) |
| 1618 data[i + dstOffset] = characters8()[i + srcSegmentStart]; | 1618 data[i + dstOffset] = characters8()[i + srcSegmentStart]; |
| 1619 | 1619 |
| 1620 dstOffset += srcSegmentLength; | 1620 dstOffset += srcSegmentLength; |
| 1621 memcpy(data + dstOffset, replacement, repStrLength * sizeof(UChar)); | 1621 memcpy(data + dstOffset, replacement, repStrLength * sizeof(UChar)); |
| 1622 | 1622 |
| 1623 dstOffset += repStrLength; | 1623 dstOffset += repStrLength; |
| 1624 srcSegmentStart = srcSegmentEnd + 1; | 1624 srcSegmentStart = srcSegmentEnd + 1; |
| 1625 } | 1625 } |
| 1626 | 1626 |
| 1627 srcSegmentLength = m_length - srcSegmentStart; | 1627 srcSegmentLength = m_length - srcSegmentStart; |
| 1628 for (unsigned i = 0; i < srcSegmentLength; ++i) | 1628 for (unsigned i = 0; i < srcSegmentLength; ++i) |
| 1629 data[i + dstOffset] = characters8()[i + srcSegmentStart]; | 1629 data[i + dstOffset] = characters8()[i + srcSegmentStart]; |
| 1630 | 1630 |
| 1631 ASSERT(dstOffset + srcSegmentLength == newImpl->length()); | 1631 ASSERT(dstOffset + srcSegmentLength == newImpl->length()); |
| 1632 | 1632 |
| 1633 return newImpl.release(); | 1633 return newImpl.release(); |
| 1634 } | 1634 } |
| 1635 | 1635 |
| 1636 UChar* data; | 1636 UChar* data; |
| 1637 RefPtr<StringImpl> newImpl = createUninitialized(newSize, data); | 1637 RefPtr<StringImpl> newImpl = createUninitialized(newSize, data); |
| 1638 | 1638 |
| 1639 while ((srcSegmentEnd = find(pattern, srcSegmentStart)) != notFound) { | 1639 while ((srcSegmentEnd = find(pattern, srcSegmentStart)) != kNotFound) { |
| 1640 srcSegmentLength = srcSegmentEnd - srcSegmentStart; | 1640 srcSegmentLength = srcSegmentEnd - srcSegmentStart; |
| 1641 memcpy(data + dstOffset, characters16() + srcSegmentStart, srcSegmentLen
gth * sizeof(UChar)); | 1641 memcpy(data + dstOffset, characters16() + srcSegmentStart, srcSegmentLen
gth * sizeof(UChar)); |
| 1642 | 1642 |
| 1643 dstOffset += srcSegmentLength; | 1643 dstOffset += srcSegmentLength; |
| 1644 memcpy(data + dstOffset, replacement, repStrLength * sizeof(UChar)); | 1644 memcpy(data + dstOffset, replacement, repStrLength * sizeof(UChar)); |
| 1645 | 1645 |
| 1646 dstOffset += repStrLength; | 1646 dstOffset += repStrLength; |
| 1647 srcSegmentStart = srcSegmentEnd + 1; | 1647 srcSegmentStart = srcSegmentEnd + 1; |
| 1648 } | 1648 } |
| 1649 | 1649 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1662 | 1662 |
| 1663 unsigned patternLength = pattern->length(); | 1663 unsigned patternLength = pattern->length(); |
| 1664 if (!patternLength) | 1664 if (!patternLength) |
| 1665 return this; | 1665 return this; |
| 1666 | 1666 |
| 1667 unsigned repStrLength = replacement->length(); | 1667 unsigned repStrLength = replacement->length(); |
| 1668 size_t srcSegmentStart = 0; | 1668 size_t srcSegmentStart = 0; |
| 1669 unsigned matchCount = 0; | 1669 unsigned matchCount = 0; |
| 1670 | 1670 |
| 1671 // Count the matches. | 1671 // Count the matches. |
| 1672 while ((srcSegmentStart = find(pattern, srcSegmentStart)) != notFound) { | 1672 while ((srcSegmentStart = find(pattern, srcSegmentStart)) != kNotFound) { |
| 1673 ++matchCount; | 1673 ++matchCount; |
| 1674 srcSegmentStart += patternLength; | 1674 srcSegmentStart += patternLength; |
| 1675 } | 1675 } |
| 1676 | 1676 |
| 1677 // If we have 0 matches, we don't have to do any more work | 1677 // If we have 0 matches, we don't have to do any more work |
| 1678 if (!matchCount) | 1678 if (!matchCount) |
| 1679 return this; | 1679 return this; |
| 1680 | 1680 |
| 1681 unsigned newSize = m_length - matchCount * patternLength; | 1681 unsigned newSize = m_length - matchCount * patternLength; |
| 1682 RELEASE_ASSERT(!repStrLength || matchCount <= numeric_limits<unsigned>::max(
) / repStrLength); | 1682 RELEASE_ASSERT(!repStrLength || matchCount <= numeric_limits<unsigned>::max(
) / repStrLength); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1696 | 1696 |
| 1697 // There are 4 cases: | 1697 // There are 4 cases: |
| 1698 // 1. This and replacement are both 8 bit. | 1698 // 1. This and replacement are both 8 bit. |
| 1699 // 2. This and replacement are both 16 bit. | 1699 // 2. This and replacement are both 16 bit. |
| 1700 // 3. This is 8 bit and replacement is 16 bit. | 1700 // 3. This is 8 bit and replacement is 16 bit. |
| 1701 // 4. This is 16 bit and replacement is 8 bit. | 1701 // 4. This is 16 bit and replacement is 8 bit. |
| 1702 if (srcIs8Bit && replacementIs8Bit) { | 1702 if (srcIs8Bit && replacementIs8Bit) { |
| 1703 // Case 1 | 1703 // Case 1 |
| 1704 LChar* data; | 1704 LChar* data; |
| 1705 RefPtr<StringImpl> newImpl = createUninitialized(newSize, data); | 1705 RefPtr<StringImpl> newImpl = createUninitialized(newSize, data); |
| 1706 while ((srcSegmentEnd = find(pattern, srcSegmentStart)) != notFound) { | 1706 while ((srcSegmentEnd = find(pattern, srcSegmentStart)) != kNotFound) { |
| 1707 srcSegmentLength = srcSegmentEnd - srcSegmentStart; | 1707 srcSegmentLength = srcSegmentEnd - srcSegmentStart; |
| 1708 memcpy(data + dstOffset, characters8() + srcSegmentStart, srcSegment
Length * sizeof(LChar)); | 1708 memcpy(data + dstOffset, characters8() + srcSegmentStart, srcSegment
Length * sizeof(LChar)); |
| 1709 dstOffset += srcSegmentLength; | 1709 dstOffset += srcSegmentLength; |
| 1710 memcpy(data + dstOffset, replacement->characters8(), repStrLength *
sizeof(LChar)); | 1710 memcpy(data + dstOffset, replacement->characters8(), repStrLength *
sizeof(LChar)); |
| 1711 dstOffset += repStrLength; | 1711 dstOffset += repStrLength; |
| 1712 srcSegmentStart = srcSegmentEnd + patternLength; | 1712 srcSegmentStart = srcSegmentEnd + patternLength; |
| 1713 } | 1713 } |
| 1714 | 1714 |
| 1715 srcSegmentLength = m_length - srcSegmentStart; | 1715 srcSegmentLength = m_length - srcSegmentStart; |
| 1716 memcpy(data + dstOffset, characters8() + srcSegmentStart, srcSegmentLeng
th * sizeof(LChar)); | 1716 memcpy(data + dstOffset, characters8() + srcSegmentStart, srcSegmentLeng
th * sizeof(LChar)); |
| 1717 | 1717 |
| 1718 ASSERT(dstOffset + srcSegmentLength == newImpl->length()); | 1718 ASSERT(dstOffset + srcSegmentLength == newImpl->length()); |
| 1719 | 1719 |
| 1720 return newImpl.release(); | 1720 return newImpl.release(); |
| 1721 } | 1721 } |
| 1722 | 1722 |
| 1723 UChar* data; | 1723 UChar* data; |
| 1724 RefPtr<StringImpl> newImpl = createUninitialized(newSize, data); | 1724 RefPtr<StringImpl> newImpl = createUninitialized(newSize, data); |
| 1725 while ((srcSegmentEnd = find(pattern, srcSegmentStart)) != notFound) { | 1725 while ((srcSegmentEnd = find(pattern, srcSegmentStart)) != kNotFound) { |
| 1726 srcSegmentLength = srcSegmentEnd - srcSegmentStart; | 1726 srcSegmentLength = srcSegmentEnd - srcSegmentStart; |
| 1727 if (srcIs8Bit) { | 1727 if (srcIs8Bit) { |
| 1728 // Case 3. | 1728 // Case 3. |
| 1729 for (unsigned i = 0; i < srcSegmentLength; ++i) | 1729 for (unsigned i = 0; i < srcSegmentLength; ++i) |
| 1730 data[i + dstOffset] = characters8()[i + srcSegmentStart]; | 1730 data[i + dstOffset] = characters8()[i + srcSegmentStart]; |
| 1731 } else { | 1731 } else { |
| 1732 // Case 2 & 4. | 1732 // Case 2 & 4. |
| 1733 memcpy(data + dstOffset, characters16() + srcSegmentStart, srcSegmen
tLength * sizeof(UChar)); | 1733 memcpy(data + dstOffset, characters16() + srcSegmentStart, srcSegmen
tLength * sizeof(UChar)); |
| 1734 } | 1734 } |
| 1735 dstOffset += srcSegmentLength; | 1735 dstOffset += srcSegmentLength; |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1977 | 1977 |
| 1978 size_t StringImpl::sizeInBytes() const | 1978 size_t StringImpl::sizeInBytes() const |
| 1979 { | 1979 { |
| 1980 size_t size = length(); | 1980 size_t size = length(); |
| 1981 if (!is8Bit()) | 1981 if (!is8Bit()) |
| 1982 size *= 2; | 1982 size *= 2; |
| 1983 return size + sizeof(*this); | 1983 return size + sizeof(*this); |
| 1984 } | 1984 } |
| 1985 | 1985 |
| 1986 } // namespace WTF | 1986 } // namespace WTF |
| OLD | NEW |