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" | |
41 #include "contexts.h" | 40 #include "contexts.h" |
42 #include "conversions-inl.h" | 41 #include "conversions-inl.h" |
43 #include "heap.h" | 42 #include "heap.h" |
44 #include "isolate.h" | 43 #include "isolate.h" |
45 #include "property.h" | 44 #include "property.h" |
46 #include "spaces.h" | 45 #include "spaces.h" |
47 #include "store-buffer.h" | 46 #include "store-buffer.h" |
48 #include "v8memory.h" | 47 #include "v8memory.h" |
49 | 48 |
50 #include "incremental-marking.h" | 49 #include "incremental-marking.h" |
(...skipping 4160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4211 // Slow case: compute hash code and set it. | 4210 // Slow case: compute hash code and set it. |
4212 return ComputeAndSetHash(); | 4211 return ComputeAndSetHash(); |
4213 } | 4212 } |
4214 | 4213 |
4215 | 4214 |
4216 StringHasher::StringHasher(int length) | 4215 StringHasher::StringHasher(int length) |
4217 : length_(length), | 4216 : length_(length), |
4218 raw_running_hash_(0), | 4217 raw_running_hash_(0), |
4219 array_index_(0), | 4218 array_index_(0), |
4220 is_array_index_(0 < length_ && length_ <= String::kMaxArrayIndexSize), | 4219 is_array_index_(0 < length_ && length_ <= String::kMaxArrayIndexSize), |
| 4220 is_first_char_(true), |
4221 is_valid_(true) { } | 4221 is_valid_(true) { } |
4222 | 4222 |
4223 | 4223 |
4224 bool StringHasher::has_trivial_hash() { | 4224 bool StringHasher::has_trivial_hash() { |
4225 return length_ > String::kMaxHashCalcLength; | 4225 return length_ > String::kMaxHashCalcLength; |
4226 } | 4226 } |
4227 | 4227 |
4228 | 4228 |
4229 void StringHasher::AddCharacter(uc32 c) { | 4229 void StringHasher::AddCharacter(uc32 c) { |
4230 // Use the Jenkins one-at-a-time hash function to update the hash | 4230 // Use the Jenkins one-at-a-time hash function to update the hash |
4231 // for the given character. | 4231 // for the given character. |
4232 raw_running_hash_ = (raw_running_hash_ + c) * 1025; | 4232 raw_running_hash_ += c; |
| 4233 raw_running_hash_ += (raw_running_hash_ << 10); |
4233 raw_running_hash_ ^= (raw_running_hash_ >> 6); | 4234 raw_running_hash_ ^= (raw_running_hash_ >> 6); |
| 4235 // Incremental array index computation. |
4234 if (is_array_index_) { | 4236 if (is_array_index_) { |
4235 // Incremental array index computation. | 4237 if (c < '0' || c > '9') { |
4236 unsigned digit = static_cast<unsigned>(c) - '0'; | |
4237 if (digit > 9 || array_index_ > 429496729U - ((digit + 2) >> 3)) { | |
4238 is_array_index_ = false; | 4238 is_array_index_ = false; |
4239 } else { | 4239 } else { |
4240 array_index_ = array_index_ * 10 + digit; | 4240 int d = c - '0'; |
4241 // Check for overflows or prefixed zeros (lengths > 0). | 4241 if (is_first_char_) { |
4242 if (array_index_ == 0 && length_ > 1) { | 4242 is_first_char_ = false; |
| 4243 if (c == '0' && length_ > 1) { |
| 4244 is_array_index_ = false; |
| 4245 return; |
| 4246 } |
| 4247 } |
| 4248 if (array_index_ > 429496729U - ((d + 2) >> 3)) { |
4243 is_array_index_ = false; | 4249 is_array_index_ = false; |
| 4250 } else { |
| 4251 array_index_ = array_index_ * 10 + d; |
4244 } | 4252 } |
4245 } | 4253 } |
4246 } | 4254 } |
4247 } | 4255 } |
4248 | 4256 |
4249 | 4257 |
4250 void StringHasher::AddCharacterNoIndex(uc32 c) { | 4258 void StringHasher::AddCharacterNoIndex(uc32 c) { |
4251 ASSERT(!is_array_index()); | 4259 ASSERT(!is_array_index()); |
4252 raw_running_hash_ = (raw_running_hash_ + c) * 1025; | 4260 raw_running_hash_ += c; |
| 4261 raw_running_hash_ += (raw_running_hash_ << 10); |
4253 raw_running_hash_ ^= (raw_running_hash_ >> 6); | 4262 raw_running_hash_ ^= (raw_running_hash_ >> 6); |
4254 } | 4263 } |
4255 | 4264 |
4256 | 4265 |
4257 uint32_t StringHasher::GetHash() { | 4266 uint32_t StringHasher::GetHash() { |
4258 // Get the calculated raw hash value and do some more bit ops to distribute | 4267 // Get the calculated raw hash value and do some more bit ops to distribute |
4259 // the hash further. Ensure that we never return zero as the hash value. | 4268 // the hash further. Ensure that we never return zero as the hash value. |
4260 uint32_t result = raw_running_hash_; | 4269 uint32_t result = raw_running_hash_; |
4261 result += (result << 3); | 4270 result += (result << 3); |
4262 result ^= (result >> 11); | 4271 result ^= (result >> 11); |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4632 #undef WRITE_INT_FIELD | 4641 #undef WRITE_INT_FIELD |
4633 #undef READ_SHORT_FIELD | 4642 #undef READ_SHORT_FIELD |
4634 #undef WRITE_SHORT_FIELD | 4643 #undef WRITE_SHORT_FIELD |
4635 #undef READ_BYTE_FIELD | 4644 #undef READ_BYTE_FIELD |
4636 #undef WRITE_BYTE_FIELD | 4645 #undef WRITE_BYTE_FIELD |
4637 | 4646 |
4638 | 4647 |
4639 } } // namespace v8::internal | 4648 } } // namespace v8::internal |
4640 | 4649 |
4641 #endif // V8_OBJECTS_INL_H_ | 4650 #endif // V8_OBJECTS_INL_H_ |
OLD | NEW |