OLD | NEW |
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 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 4971 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4982 // Isolate the array index form the full hash field. | 4982 // Isolate the array index form the full hash field. |
4983 *index = (kArrayIndexHashMask & field) >> kHashShift; | 4983 *index = (kArrayIndexHashMask & field) >> kHashShift; |
4984 return true; | 4984 return true; |
4985 } else { | 4985 } else { |
4986 StringInputBuffer buffer(this); | 4986 StringInputBuffer buffer(this); |
4987 return ComputeArrayIndex(&buffer, index, length()); | 4987 return ComputeArrayIndex(&buffer, index, length()); |
4988 } | 4988 } |
4989 } | 4989 } |
4990 | 4990 |
4991 | 4991 |
4992 static inline uint32_t HashField(uint32_t hash, | 4992 uint32_t StringHasher::MakeCachedArrayIndex(uint32_t value, int length) { |
4993 bool is_array_index, | 4993 value <<= String::kHashShift; |
4994 int length = -1) { | 4994 // For array indexes mix the length into the hash as an array index could |
4995 uint32_t result = (hash << String::kHashShift); | 4995 // be zero. |
4996 if (is_array_index) { | 4996 ASSERT(length > 0); |
4997 // For array indexes mix the length into the hash as an array index could | 4997 ASSERT(length <= String::kMaxArrayIndexSize); |
4998 // be zero. | 4998 ASSERT(TenToThe(String::kMaxCachedArrayIndexLength) < |
4999 ASSERT(length > 0); | 4999 (1 << String::kArrayIndexValueBits)); |
5000 ASSERT(length <= String::kMaxArrayIndexSize); | 5000 ASSERT(String::kMaxArrayIndexSize < (1 << String::kArrayIndexValueBits)); |
5001 ASSERT(TenToThe(String::kMaxCachedArrayIndexLength) < | 5001 value &= ~String::kIsNotArrayIndexMask; |
5002 (1 << String::kArrayIndexValueBits)); | 5002 value |= length << String::kArrayIndexHashLengthShift; |
5003 ASSERT(String::kMaxArrayIndexSize < (1 << String::kArrayIndexValueBits)); | 5003 return value; |
5004 result &= ~String::kIsNotArrayIndexMask; | |
5005 result |= length << String::kArrayIndexHashLengthShift; | |
5006 } else { | |
5007 result |= String::kIsNotArrayIndexMask; | |
5008 } | |
5009 return result; | |
5010 } | 5004 } |
5011 | 5005 |
5012 | 5006 |
5013 uint32_t StringHasher::GetHashField() { | 5007 uint32_t StringHasher::GetHashField() { |
5014 ASSERT(is_valid()); | 5008 ASSERT(is_valid()); |
5015 if (length_ <= String::kMaxHashCalcLength) { | 5009 if (length_ <= String::kMaxHashCalcLength) { |
5016 if (is_array_index()) { | 5010 if (is_array_index()) { |
5017 return v8::internal::HashField(array_index(), true, length_); | 5011 return MakeCachedArrayIndex(array_index(), length_); |
5018 } else { | |
5019 return v8::internal::HashField(GetHash(), false); | |
5020 } | 5012 } |
5021 uint32_t payload = v8::internal::HashField(GetHash(), false); | 5013 return (GetHash() << String::kHashShift) | String::kIsNotArrayIndexMask; |
5022 return payload; | |
5023 } else { | 5014 } else { |
5024 return v8::internal::HashField(length_, false); | 5015 return (length_ << String::kHashShift) | String::kIsNotArrayIndexMask; |
5025 } | 5016 } |
5026 } | 5017 } |
5027 | 5018 |
5028 | 5019 |
5029 uint32_t String::ComputeHashField(unibrow::CharacterStream* buffer, | 5020 uint32_t String::ComputeHashField(unibrow::CharacterStream* buffer, |
5030 int length) { | 5021 int length) { |
5031 StringHasher hasher(length); | 5022 StringHasher hasher(length); |
5032 | 5023 |
5033 // Very long strings have a trivial hash that doesn't inspect the | 5024 // Very long strings have a trivial hash that doesn't inspect the |
5034 // string contents. | 5025 // string contents. |
(...skipping 3861 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8896 if (break_point_objects()->IsUndefined()) return 0; | 8887 if (break_point_objects()->IsUndefined()) return 0; |
8897 // Single beak point. | 8888 // Single beak point. |
8898 if (!break_point_objects()->IsFixedArray()) return 1; | 8889 if (!break_point_objects()->IsFixedArray()) return 1; |
8899 // Multiple break points. | 8890 // Multiple break points. |
8900 return FixedArray::cast(break_point_objects())->length(); | 8891 return FixedArray::cast(break_point_objects())->length(); |
8901 } | 8892 } |
8902 #endif | 8893 #endif |
8903 | 8894 |
8904 | 8895 |
8905 } } // namespace v8::internal | 8896 } } // namespace v8::internal |
OLD | NEW |