Changeset 69449 in webkit
- Timestamp:
- Oct 9, 2010 8:32:07 AM (13 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r69448 r69449 1 2010-10-09 Patrick Gansterer <paroga@webkit.org> 2 3 Reviewed by Adam Barth. 4 5 Use WTF::StringHasher for hashing MappedAttributeKey 6 https://bugs.webkit.org/show_bug.cgi?id=46516 7 8 * dom/StyledElement.cpp: 9 (WebCore::MappedAttributeHash::hash): 10 1 11 2010-10-09 Martin Robinson <mrobinson@igalia.com> 2 12 -
trunk/WebCore/dom/StyledElement.cpp
r69044 r69449 403 403 } 404 404 405 // Paul Hsieh's SuperFastHash406 // http://www.azillionmonkeys.com/qed/hash.html407 405 unsigned MappedAttributeHash::hash(const MappedAttributeKey& key) 408 406 { 409 uint32_t hash = WTF::stringHashingStartValue; 410 uint32_t tmp; 411 412 const uint16_t* p; 413 414 p = reinterpret_cast<const uint16_t*>(&key.name); 415 hash += p[0]; 416 tmp = (p[1] << 11) ^ hash; 417 hash = (hash << 16) ^ tmp; 418 hash += hash >> 11; 419 ASSERT(sizeof(key.name) == 4 || sizeof(key.name) == 8); 420 if (sizeof(key.name) == 8) { 421 p += 2; 422 hash += p[0]; 423 tmp = (p[1] << 11) ^ hash; 424 hash = (hash << 16) ^ tmp; 425 hash += hash >> 11; 426 } 427 428 p = reinterpret_cast<const uint16_t*>(&key.value); 429 hash += p[0]; 430 tmp = (p[1] << 11) ^ hash; 431 hash = (hash << 16) ^ tmp; 432 hash += hash >> 11; 433 ASSERT(sizeof(key.value) == 4 || sizeof(key.value) == 8); 434 if (sizeof(key.value) == 8) { 435 p += 2; 436 hash += p[0]; 437 tmp = (p[1] << 11) ^ hash; 438 hash = (hash << 16) ^ tmp; 439 hash += hash >> 11; 440 } 441 442 // Handle end case 443 hash += key.type; 444 hash ^= hash << 11; 445 hash += hash >> 17; 446 447 // Force "avalanching" of final 127 bits 448 hash ^= hash << 3; 449 hash += hash >> 5; 450 hash ^= hash << 2; 451 hash += hash >> 15; 452 hash ^= hash << 10; 453 454 // This avoids ever returning a hash code of 0, since that is used to 455 // signal "hash not computed yet", using a value that is likely to be 456 // effectively the same as 0 when the low bits are masked 457 if (hash == 0) 458 hash = 0x80000000; 459 460 return hash; 407 COMPILE_ASSERT(sizeof(key.name) == 4 || sizeof(key.name) == 8, key_name_size); 408 COMPILE_ASSERT(sizeof(key.value) == 4 || sizeof(key.value) == 8, key_value_size); 409 410 WTF::StringHasher hasher; 411 const UChar* data; 412 413 data = reinterpret_cast<const UChar*>(&key.name); 414 hasher.addCharacters(data[0], data[1]); 415 if (sizeof(key.name) == 8) 416 hasher.addCharacters(data[2], data[3]); 417 418 data = reinterpret_cast<const UChar*>(&key.value); 419 hasher.addCharacters(data[0], data[1]); 420 if (sizeof(key.value) == 8) 421 hasher.addCharacters(data[2], data[3]); 422 423 return hasher.hash(); 461 424 } 462 425
Note: See TracChangeset
for help on using the changeset viewer.