| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 2426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2437 | 2437 |
| 2438 void StringHasher::AddCharacterNoIndex(uc32 c) { | 2438 void StringHasher::AddCharacterNoIndex(uc32 c) { |
| 2439 ASSERT(!is_array_index()); | 2439 ASSERT(!is_array_index()); |
| 2440 raw_running_hash_ += c; | 2440 raw_running_hash_ += c; |
| 2441 raw_running_hash_ += (raw_running_hash_ << 10); | 2441 raw_running_hash_ += (raw_running_hash_ << 10); |
| 2442 raw_running_hash_ ^= (raw_running_hash_ >> 6); | 2442 raw_running_hash_ ^= (raw_running_hash_ >> 6); |
| 2443 } | 2443 } |
| 2444 | 2444 |
| 2445 | 2445 |
| 2446 uint32_t StringHasher::GetHash() { | 2446 uint32_t StringHasher::GetHash() { |
| 2447 // Get the calculated raw hash value and do some more bit ops to distribute |
| 2448 // the hash further. Ensure that we never return zero as the hash value. |
| 2447 uint32_t result = raw_running_hash_; | 2449 uint32_t result = raw_running_hash_; |
| 2448 result += (result << 3); | 2450 result += (result << 3); |
| 2449 result ^= (result >> 11); | 2451 result ^= (result >> 11); |
| 2450 result += (result << 15); | 2452 result += (result << 15); |
| 2453 if (result == 0) { |
| 2454 result = 27; |
| 2455 } |
| 2451 return result; | 2456 return result; |
| 2452 } | 2457 } |
| 2453 | 2458 |
| 2454 | 2459 |
| 2455 bool String::AsArrayIndex(uint32_t* index) { | 2460 bool String::AsArrayIndex(uint32_t* index) { |
| 2456 uint32_t field = length_field(); | 2461 uint32_t field = length_field(); |
| 2457 if ((field & kHashComputedMask) && !(field & kIsArrayIndexMask)) return false; | 2462 if ((field & kHashComputedMask) && !(field & kIsArrayIndexMask)) return false; |
| 2458 return SlowAsArrayIndex(index); | 2463 return SlowAsArrayIndex(index); |
| 2459 } | 2464 } |
| 2460 | 2465 |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2566 #undef WRITE_INT_FIELD | 2571 #undef WRITE_INT_FIELD |
| 2567 #undef READ_SHORT_FIELD | 2572 #undef READ_SHORT_FIELD |
| 2568 #undef WRITE_SHORT_FIELD | 2573 #undef WRITE_SHORT_FIELD |
| 2569 #undef READ_BYTE_FIELD | 2574 #undef READ_BYTE_FIELD |
| 2570 #undef WRITE_BYTE_FIELD | 2575 #undef WRITE_BYTE_FIELD |
| 2571 | 2576 |
| 2572 | 2577 |
| 2573 } } // namespace v8::internal | 2578 } } // namespace v8::internal |
| 2574 | 2579 |
| 2575 #endif // V8_OBJECTS_INL_H_ | 2580 #endif // V8_OBJECTS_INL_H_ |
| OLD | NEW |