Changeset 62148 in webkit for trunk/JavaScriptCore/runtime/UString.h
- Timestamp:
- Jun 29, 2010, 3:01:29 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/runtime/UString.h
r60332 r62148 159 159 ALWAYS_INLINE bool operator==(const UString& s1, const UString& s2) 160 160 { 161 unsigned size = s1.size(); 162 switch (size) { 163 case 0: 164 return !s2.size(); 161 UString::Rep* rep1 = s1.rep(); 162 UString::Rep* rep2 = s2.rep(); 163 unsigned size1 = 0; 164 unsigned size2 = 0; 165 166 if (rep1 == rep2) // If they're the same rep, they're equal. 167 return true; 168 169 if (rep1) 170 size1 = rep1->length(); 171 172 if (rep2) 173 size2 = rep2->length(); 174 175 if (size1 != size2) // If the lengths are not the same, we're done. 176 return false; 177 178 if (!size1) 179 return true; 180 181 // At this point we know 182 // (a) that the strings are the same length and 183 // (b) that they are greater than zero length. 184 const UChar* d1 = rep1->characters(); 185 const UChar* d2 = rep2->characters(); 186 187 if (d1 == d2) // Check to see if the data pointers are the same. 188 return true; 189 190 // Do quick checks for sizes 1 and 2. 191 switch (size1) { 165 192 case 1: 166 return s2.size() == 1 && s1.data()[0] == s2.data()[0]; 167 case 2: { 168 if (s2.size() != 2) 169 return false; 170 const UChar* d1 = s1.data(); 171 const UChar* d2 = s2.data(); 193 return d1[0] == d2[0]; 194 case 2: 172 195 return (d1[0] == d2[0]) & (d1[1] == d2[1]); 173 }174 196 default: 175 return s2.size() == size && memcmp(s1.data(), s2.data(), size* sizeof(UChar)) == 0;197 return memcmp(d1, d2, size1 * sizeof(UChar)) == 0; 176 198 } 177 199 }
Note:
See TracChangeset
for help on using the changeset viewer.