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 4137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4187 // Slow case: compute hash code and set it. | 4188 // Slow case: compute hash code and set it. |
4188 return ComputeAndSetHash(); | 4189 return ComputeAndSetHash(); |
4189 } | 4190 } |
4190 | 4191 |
4191 | 4192 |
4192 StringHasher::StringHasher(int length) | 4193 StringHasher::StringHasher(int length) |
4193 : length_(length), | 4194 : length_(length), |
4194 raw_running_hash_(0), | 4195 raw_running_hash_(0), |
4195 array_index_(0), | 4196 array_index_(0), |
4196 is_array_index_(0 < length_ && length_ <= String::kMaxArrayIndexSize), | 4197 is_array_index_(0 < length_ && length_ <= String::kMaxArrayIndexSize), |
4197 is_first_char_(true), | |
4198 is_valid_(true) { } | 4198 is_valid_(true) { } |
4199 | 4199 |
4200 | 4200 |
4201 bool StringHasher::has_trivial_hash() { | 4201 bool StringHasher::has_trivial_hash() { |
4202 return length_ > String::kMaxHashCalcLength; | 4202 return length_ > String::kMaxHashCalcLength; |
4203 } | 4203 } |
4204 | 4204 |
4205 | 4205 |
4206 void StringHasher::AddCharacter(uc32 c) { | 4206 void StringHasher::AddCharacter(uc32 c) { |
4207 // Use the Jenkins one-at-a-time hash function to update the hash | 4207 // Use the Jenkins one-at-a-time hash function to update the hash |
4208 // for the given character. | 4208 // for the given character. |
4209 raw_running_hash_ += c; | 4209 raw_running_hash_ = (raw_running_hash_ + c) * 1025; |
4210 raw_running_hash_ += (raw_running_hash_ << 10); | |
4211 raw_running_hash_ ^= (raw_running_hash_ >> 6); | 4210 raw_running_hash_ ^= (raw_running_hash_ >> 6); |
4212 // Incremental array index computation. | |
4213 if (is_array_index_) { | 4211 if (is_array_index_) { |
4214 if (c < '0' || c > '9') { | 4212 // Incremental array index computation. |
| 4213 unsigned digit = static_cast<unsigned>(c) - '0'; |
| 4214 if (digit > 9 || array_index_ > 429496729U - ((digit + 2) >> 3)) { |
4215 is_array_index_ = false; | 4215 is_array_index_ = false; |
4216 } else { | 4216 } else { |
4217 int d = c - '0'; | 4217 array_index_ = array_index_ * 10 + digit; |
4218 if (is_first_char_) { | 4218 // Check for overflows or prefixed zeros (lengths > 0). |
4219 is_first_char_ = false; | 4219 if (array_index_ == 0 && length_ > 1) { |
4220 if (c == '0' && length_ > 1) { | |
4221 is_array_index_ = false; | |
4222 return; | |
4223 } | |
4224 } | |
4225 if (array_index_ > 429496729U - ((d + 2) >> 3)) { | |
4226 is_array_index_ = false; | 4220 is_array_index_ = false; |
4227 } else { | |
4228 array_index_ = array_index_ * 10 + d; | |
4229 } | 4221 } |
4230 } | 4222 } |
4231 } | 4223 } |
4232 } | 4224 } |
4233 | 4225 |
4234 | 4226 |
4235 void StringHasher::AddCharacterNoIndex(uc32 c) { | 4227 void StringHasher::AddCharacterNoIndex(uc32 c) { |
4236 ASSERT(!is_array_index()); | 4228 ASSERT(!is_array_index()); |
4237 raw_running_hash_ += c; | 4229 raw_running_hash_ = (raw_running_hash_ + c) * 1025; |
4238 raw_running_hash_ += (raw_running_hash_ << 10); | |
4239 raw_running_hash_ ^= (raw_running_hash_ >> 6); | 4230 raw_running_hash_ ^= (raw_running_hash_ >> 6); |
4240 } | 4231 } |
4241 | 4232 |
4242 | 4233 |
4243 uint32_t StringHasher::GetHash() { | 4234 uint32_t StringHasher::GetHash() { |
4244 // Get the calculated raw hash value and do some more bit ops to distribute | 4235 // Get the calculated raw hash value and do some more bit ops to distribute |
4245 // the hash further. Ensure that we never return zero as the hash value. | 4236 // the hash further. Ensure that we never return zero as the hash value. |
4246 uint32_t result = raw_running_hash_; | 4237 uint32_t result = raw_running_hash_; |
4247 result += (result << 3); | 4238 result += (result << 3); |
4248 result ^= (result >> 11); | 4239 result ^= (result >> 11); |
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4654 #undef WRITE_INT_FIELD | 4645 #undef WRITE_INT_FIELD |
4655 #undef READ_SHORT_FIELD | 4646 #undef READ_SHORT_FIELD |
4656 #undef WRITE_SHORT_FIELD | 4647 #undef WRITE_SHORT_FIELD |
4657 #undef READ_BYTE_FIELD | 4648 #undef READ_BYTE_FIELD |
4658 #undef WRITE_BYTE_FIELD | 4649 #undef WRITE_BYTE_FIELD |
4659 | 4650 |
4660 | 4651 |
4661 } } // namespace v8::internal | 4652 } } // namespace v8::internal |
4662 | 4653 |
4663 #endif // V8_OBJECTS_INL_H_ | 4654 #endif // V8_OBJECTS_INL_H_ |
OLD | NEW |