OLD | NEW |
---|---|
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 19 matching lines...) Expand all Loading... | |
30 // - The use of macros in these inline functions may seem superfluous | 30 // - The use of macros in these inline functions may seem superfluous |
31 // but it is absolutely needed to make sure gcc generates optimal | 31 // but it is absolutely needed to make sure gcc generates optimal |
32 // code. gcc is not happy when attempting to inline too deep. | 32 // code. gcc is not happy when attempting to inline too deep. |
33 // | 33 // |
34 | 34 |
35 #ifndef V8_OBJECTS_INL_H_ | 35 #ifndef V8_OBJECTS_INL_H_ |
36 #define V8_OBJECTS_INL_H_ | 36 #define V8_OBJECTS_INL_H_ |
37 | 37 |
38 #include "elements.h" | 38 #include "elements.h" |
39 #include "objects.h" | 39 #include "objects.h" |
40 #include "char-predicates-inl.h" | |
40 #include "contexts.h" | 41 #include "contexts.h" |
41 #include "conversions-inl.h" | 42 #include "conversions-inl.h" |
42 #include "heap.h" | 43 #include "heap.h" |
43 #include "isolate.h" | 44 #include "isolate.h" |
44 #include "property.h" | 45 #include "property.h" |
45 #include "spaces.h" | 46 #include "spaces.h" |
46 #include "store-buffer.h" | 47 #include "store-buffer.h" |
47 #include "v8memory.h" | 48 #include "v8memory.h" |
48 | 49 |
49 #include "incremental-marking.h" | 50 #include "incremental-marking.h" |
(...skipping 4037 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4087 // Slow case: compute hash code and set it. | 4088 // Slow case: compute hash code and set it. |
4088 return ComputeAndSetHash(); | 4089 return ComputeAndSetHash(); |
4089 } | 4090 } |
4090 | 4091 |
4091 | 4092 |
4092 StringHasher::StringHasher(int length) | 4093 StringHasher::StringHasher(int length) |
4093 : length_(length), | 4094 : length_(length), |
4094 raw_running_hash_(0), | 4095 raw_running_hash_(0), |
4095 array_index_(0), | 4096 array_index_(0), |
4096 is_array_index_(0 < length_ && length_ <= String::kMaxArrayIndexSize), | 4097 is_array_index_(0 < length_ && length_ <= String::kMaxArrayIndexSize), |
4097 is_first_char_(true), | |
4098 is_valid_(true) { } | 4098 is_valid_(true) { } |
4099 | 4099 |
4100 | 4100 |
4101 bool StringHasher::has_trivial_hash() { | 4101 bool StringHasher::has_trivial_hash() { |
4102 return length_ > String::kMaxHashCalcLength; | 4102 return length_ > String::kMaxHashCalcLength; |
4103 } | 4103 } |
4104 | 4104 |
4105 | 4105 |
4106 void StringHasher::AddCharacter(uc32 c) { | 4106 void StringHasher::AddCharacter(uc32 c) { |
4107 // Use the Jenkins one-at-a-time hash function to update the hash | 4107 // Use the Jenkins one-at-a-time hash function to update the hash |
4108 // for the given character. | 4108 // for the given character. |
4109 raw_running_hash_ += c; | 4109 raw_running_hash_ = (raw_running_hash_ + c) * 1025; |
4110 raw_running_hash_ += (raw_running_hash_ << 10); | |
4111 raw_running_hash_ ^= (raw_running_hash_ >> 6); | 4110 raw_running_hash_ ^= (raw_running_hash_ >> 6); |
4112 // Incremental array index computation. | 4111 // Incremental array index computation. |
4113 if (is_array_index_) { | 4112 ASSERT(is_array_index_); |
Rico
2011/09/23 07:06:52
I think the name of this function is not descripti
Lasse Reichstein
2011/09/23 09:54:39
I'll change this back to be an if. The *NoIndex fu
| |
4114 if (c < '0' || c > '9') { | 4113 unsigned digit = static_cast<unsigned>(c) - '0'; |
4114 if (digit > 9 || array_index_ > 429496729U - ((digit + 2) >> 3)) { | |
4115 is_array_index_ = false; | |
4116 } else { | |
4117 array_index_ = array_index_ * 10 + digit; | |
4118 // Check for overflows or prefixed zeros (lengths > 0). | |
4119 if (array_index_ == 0 && length_ > 1) { | |
4115 is_array_index_ = false; | 4120 is_array_index_ = false; |
4116 } else { | |
4117 int d = c - '0'; | |
4118 if (is_first_char_) { | |
4119 is_first_char_ = false; | |
4120 if (c == '0' && length_ > 1) { | |
4121 is_array_index_ = false; | |
4122 return; | |
4123 } | |
4124 } | |
4125 if (array_index_ > 429496729U - ((d + 2) >> 3)) { | |
4126 is_array_index_ = false; | |
4127 } else { | |
4128 array_index_ = array_index_ * 10 + d; | |
4129 } | |
4130 } | 4121 } |
4131 } | 4122 } |
4132 } | 4123 } |
4133 | 4124 |
4134 | 4125 |
4135 void StringHasher::AddCharacterNoIndex(uc32 c) { | 4126 void StringHasher::AddCharacterNoIndex(uc32 c) { |
4136 ASSERT(!is_array_index()); | 4127 ASSERT(!is_array_index()); |
4137 raw_running_hash_ += c; | 4128 raw_running_hash_ = (raw_running_hash_ + c) * 1025; |
4138 raw_running_hash_ += (raw_running_hash_ << 10); | |
4139 raw_running_hash_ ^= (raw_running_hash_ >> 6); | 4129 raw_running_hash_ ^= (raw_running_hash_ >> 6); |
4140 } | 4130 } |
4141 | 4131 |
4142 | 4132 |
4143 uint32_t StringHasher::GetHash() { | 4133 uint32_t StringHasher::GetHash() { |
4144 // Get the calculated raw hash value and do some more bit ops to distribute | 4134 // Get the calculated raw hash value and do some more bit ops to distribute |
4145 // the hash further. Ensure that we never return zero as the hash value. | 4135 // the hash further. Ensure that we never return zero as the hash value. |
4146 uint32_t result = raw_running_hash_; | 4136 uint32_t result = raw_running_hash_; |
4147 result += (result << 3); | 4137 result += (result << 3); |
4148 result ^= (result >> 11); | 4138 result ^= (result >> 11); |
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4541 #undef WRITE_INT_FIELD | 4531 #undef WRITE_INT_FIELD |
4542 #undef READ_SHORT_FIELD | 4532 #undef READ_SHORT_FIELD |
4543 #undef WRITE_SHORT_FIELD | 4533 #undef WRITE_SHORT_FIELD |
4544 #undef READ_BYTE_FIELD | 4534 #undef READ_BYTE_FIELD |
4545 #undef WRITE_BYTE_FIELD | 4535 #undef WRITE_BYTE_FIELD |
4546 | 4536 |
4547 | 4537 |
4548 } } // namespace v8::internal | 4538 } } // namespace v8::internal |
4549 | 4539 |
4550 #endif // V8_OBJECTS_INL_H_ | 4540 #endif // V8_OBJECTS_INL_H_ |
OLD | NEW |