Changeset 65479 in webkit for trunk/JavaScriptCore/runtime/UString.h
- Timestamp:
- Aug 16, 2010, 7:21:26 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/runtime/UString.h
r65478 r65479 195 195 } 196 196 197 struct UStringHash { 198 static unsigned hash(StringImpl* key) { return key->hash(); } 199 static bool equal(const StringImpl* a, const StringImpl* b) 200 { 201 if (a == b) 202 return true; 203 if (!a || !b) 204 return false; 205 206 unsigned aLength = a->length(); 207 unsigned bLength = b->length(); 208 if (aLength != bLength) 209 return false; 210 211 // FIXME: perhaps we should have a more abstract macro that indicates when 212 // going 4 bytes at a time is unsafe 213 #if CPU(ARM) || CPU(SH4) 214 const UChar* aChars = a->characters(); 215 const UChar* bChars = b->characters(); 216 for (unsigned i = 0; i != aLength; ++i) { 217 if (*aChars++ != *bChars++) 218 return false; 219 } 220 return true; 221 #else 222 /* Do it 4-bytes-at-a-time on architectures where it's safe */ 223 const uint32_t* aChars = reinterpret_cast<const uint32_t*>(a->characters()); 224 const uint32_t* bChars = reinterpret_cast<const uint32_t*>(b->characters()); 225 226 unsigned halfLength = aLength >> 1; 227 for (unsigned i = 0; i != halfLength; ++i) 228 if (*aChars++ != *bChars++) 229 return false; 230 231 if (aLength & 1 && *reinterpret_cast<const uint16_t*>(aChars) != *reinterpret_cast<const uint16_t*>(bChars)) 232 return false; 233 234 return true; 235 #endif 236 } 237 238 static unsigned hash(const RefPtr<StringImpl>& key) { return key->hash(); } 239 static bool equal(const RefPtr<StringImpl>& a, const RefPtr<StringImpl>& b) 240 { 241 return equal(a.get(), b.get()); 242 } 243 244 static unsigned hash(const UString& key) { return key.impl()->hash(); } 245 static bool equal(const UString& a, const UString& b) 246 { 247 return equal(a.impl(), b.impl()); 248 } 249 250 static const bool safeToCompareToEmptyOrDeleted = false; 251 }; 252 197 253 } // namespace JSC 198 254 199 255 namespace WTF { 200 256 257 // UStringHash is the default hash for UString 258 template<typename T> struct DefaultHash; 259 template<> struct DefaultHash<JSC::UString> { 260 typedef JSC::UStringHash Hash; 261 }; 262 201 263 template <> struct VectorTraits<JSC::UString> : SimpleClassVectorTraits 202 264 {
Note:
See TracChangeset
for help on using the changeset viewer.