| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 4419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4430 is_valid_(true) { | 4430 is_valid_(true) { |
| 4431 ASSERT(FLAG_randomize_hashes || raw_running_hash_ == 0); | 4431 ASSERT(FLAG_randomize_hashes || raw_running_hash_ == 0); |
| 4432 } | 4432 } |
| 4433 | 4433 |
| 4434 | 4434 |
| 4435 bool StringHasher::has_trivial_hash() { | 4435 bool StringHasher::has_trivial_hash() { |
| 4436 return length_ > String::kMaxHashCalcLength; | 4436 return length_ > String::kMaxHashCalcLength; |
| 4437 } | 4437 } |
| 4438 | 4438 |
| 4439 | 4439 |
| 4440 void StringHasher::AddCharacter(uc32 c) { | 4440 void StringHasher::AddCharacter(uint32_t c) { |
| 4441 if (c > unibrow::Utf16::kMaxNonSurrogateCharCode) { |
| 4442 AddSurrogatePair(c); // Not inlined. |
| 4443 return; |
| 4444 } |
| 4441 // Use the Jenkins one-at-a-time hash function to update the hash | 4445 // Use the Jenkins one-at-a-time hash function to update the hash |
| 4442 // for the given character. | 4446 // for the given character. |
| 4443 raw_running_hash_ += c; | 4447 raw_running_hash_ += c; |
| 4444 raw_running_hash_ += (raw_running_hash_ << 10); | 4448 raw_running_hash_ += (raw_running_hash_ << 10); |
| 4445 raw_running_hash_ ^= (raw_running_hash_ >> 6); | 4449 raw_running_hash_ ^= (raw_running_hash_ >> 6); |
| 4446 // Incremental array index computation. | 4450 // Incremental array index computation. |
| 4447 if (is_array_index_) { | 4451 if (is_array_index_) { |
| 4448 if (c < '0' || c > '9') { | 4452 if (c < '0' || c > '9') { |
| 4449 is_array_index_ = false; | 4453 is_array_index_ = false; |
| 4450 } else { | 4454 } else { |
| 4451 int d = c - '0'; | 4455 int d = c - '0'; |
| 4452 if (is_first_char_) { | 4456 if (is_first_char_) { |
| 4453 is_first_char_ = false; | 4457 is_first_char_ = false; |
| 4454 if (c == '0' && length_ > 1) { | 4458 if (c == '0' && length_ > 1) { |
| 4455 is_array_index_ = false; | 4459 is_array_index_ = false; |
| 4456 return; | 4460 return; |
| 4457 } | 4461 } |
| 4458 } | 4462 } |
| 4459 if (array_index_ > 429496729U - ((d + 2) >> 3)) { | 4463 if (array_index_ > 429496729U - ((d + 2) >> 3)) { |
| 4460 is_array_index_ = false; | 4464 is_array_index_ = false; |
| 4461 } else { | 4465 } else { |
| 4462 array_index_ = array_index_ * 10 + d; | 4466 array_index_ = array_index_ * 10 + d; |
| 4463 } | 4467 } |
| 4464 } | 4468 } |
| 4465 } | 4469 } |
| 4466 } | 4470 } |
| 4467 | 4471 |
| 4468 | 4472 |
| 4469 void StringHasher::AddCharacterNoIndex(uc32 c) { | 4473 void StringHasher::AddCharacterNoIndex(uint32_t c) { |
| 4470 ASSERT(!is_array_index()); | 4474 ASSERT(!is_array_index()); |
| 4475 if (c > unibrow::Utf16::kMaxNonSurrogateCharCode) { |
| 4476 AddSurrogatePairNoIndex(c); // Not inlined. |
| 4477 return; |
| 4478 } |
| 4471 raw_running_hash_ += c; | 4479 raw_running_hash_ += c; |
| 4472 raw_running_hash_ += (raw_running_hash_ << 10); | 4480 raw_running_hash_ += (raw_running_hash_ << 10); |
| 4473 raw_running_hash_ ^= (raw_running_hash_ >> 6); | 4481 raw_running_hash_ ^= (raw_running_hash_ >> 6); |
| 4474 } | 4482 } |
| 4475 | 4483 |
| 4476 | 4484 |
| 4477 uint32_t StringHasher::GetHash() { | 4485 uint32_t StringHasher::GetHash() { |
| 4478 // Get the calculated raw hash value and do some more bit ops to distribute | 4486 // Get the calculated raw hash value and do some more bit ops to distribute |
| 4479 // the hash further. Ensure that we never return zero as the hash value. | 4487 // the hash further. Ensure that we never return zero as the hash value. |
| 4480 uint32_t result = raw_running_hash_; | 4488 uint32_t result = raw_running_hash_; |
| (...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4925 #undef WRITE_INT_FIELD | 4933 #undef WRITE_INT_FIELD |
| 4926 #undef READ_SHORT_FIELD | 4934 #undef READ_SHORT_FIELD |
| 4927 #undef WRITE_SHORT_FIELD | 4935 #undef WRITE_SHORT_FIELD |
| 4928 #undef READ_BYTE_FIELD | 4936 #undef READ_BYTE_FIELD |
| 4929 #undef WRITE_BYTE_FIELD | 4937 #undef WRITE_BYTE_FIELD |
| 4930 | 4938 |
| 4931 | 4939 |
| 4932 } } // namespace v8::internal | 4940 } } // namespace v8::internal |
| 4933 | 4941 |
| 4934 #endif // V8_OBJECTS_INL_H_ | 4942 #endif // V8_OBJECTS_INL_H_ |
| OLD | NEW |