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 5716 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5727 DISALLOW_IMPLICIT_CONSTRUCTORS(PolymorphicCodeCacheHashTable); | 5727 DISALLOW_IMPLICIT_CONSTRUCTORS(PolymorphicCodeCacheHashTable); |
5728 }; | 5728 }; |
5729 | 5729 |
5730 | 5730 |
5731 enum AllowNullsFlag {ALLOW_NULLS, DISALLOW_NULLS}; | 5731 enum AllowNullsFlag {ALLOW_NULLS, DISALLOW_NULLS}; |
5732 enum RobustnessFlag {ROBUST_STRING_TRAVERSAL, FAST_STRING_TRAVERSAL}; | 5732 enum RobustnessFlag {ROBUST_STRING_TRAVERSAL, FAST_STRING_TRAVERSAL}; |
5733 | 5733 |
5734 | 5734 |
5735 class StringHasher { | 5735 class StringHasher { |
5736 public: | 5736 public: |
5737 explicit inline StringHasher(int length); | 5737 explicit inline StringHasher(int length, uint32_t seed); |
5738 | 5738 |
5739 // Returns true if the hash of this string can be computed without | 5739 // Returns true if the hash of this string can be computed without |
5740 // looking at the contents. | 5740 // looking at the contents. |
5741 inline bool has_trivial_hash(); | 5741 inline bool has_trivial_hash(); |
5742 | 5742 |
5743 // Add a character to the hash and update the array index calculation. | 5743 // Add a character to the hash and update the array index calculation. |
5744 inline void AddCharacter(uc32 c); | 5744 inline void AddCharacter(uc32 c); |
5745 | 5745 |
5746 // Adds a character to the hash but does not update the array index | 5746 // Adds a character to the hash but does not update the array index |
5747 // calculation. This can only be called when it has been verified | 5747 // calculation. This can only be called when it has been verified |
(...skipping 30 matching lines...) Expand all Loading... | |
5778 uint32_t array_index_; | 5778 uint32_t array_index_; |
5779 bool is_array_index_; | 5779 bool is_array_index_; |
5780 bool is_first_char_; | 5780 bool is_first_char_; |
5781 bool is_valid_; | 5781 bool is_valid_; |
5782 friend class TwoCharHashTableKey; | 5782 friend class TwoCharHashTableKey; |
5783 }; | 5783 }; |
5784 | 5784 |
5785 | 5785 |
5786 // Calculates string hash. | 5786 // Calculates string hash. |
5787 template <typename schar> | 5787 template <typename schar> |
5788 inline uint32_t HashSequentialString(const schar* chars, int length); | 5788 inline uint32_t HashSequentialString(const schar* chars, |
5789 int length, | |
5790 uint32_t seed); | |
5789 | 5791 |
5790 | 5792 |
5791 // The characteristics of a string are stored in its map. Retrieving these | 5793 // The characteristics of a string are stored in its map. Retrieving these |
5792 // few bits of information is moderately expensive, involving two memory | 5794 // few bits of information is moderately expensive, involving two memory |
5793 // loads where the second is dependent on the first. To improve efficiency | 5795 // loads where the second is dependent on the first. To improve efficiency |
5794 // the shape of the string is given its own class so that it can be retrieved | 5796 // the shape of the string is given its own class so that it can be retrieved |
5795 // once and used for several string operations. A StringShape is small enough | 5797 // once and used for several string operations. A StringShape is small enough |
5796 // to be passed by value and is immutable, but be aware that flattening a | 5798 // to be passed by value and is immutable, but be aware that flattening a |
5797 // string can potentially alter its shape. Also be aware that a GC caused by | 5799 // string can potentially alter its shape. Also be aware that a GC caused by |
5798 // something else can alter the shape of a string due to ConsString | 5800 // something else can alter the shape of a string due to ConsString |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6000 SmartArrayPointer<uc16> ToWideCString( | 6002 SmartArrayPointer<uc16> ToWideCString( |
6001 RobustnessFlag robustness_flag = FAST_STRING_TRAVERSAL); | 6003 RobustnessFlag robustness_flag = FAST_STRING_TRAVERSAL); |
6002 | 6004 |
6003 // Tells whether the hash code has been computed. | 6005 // Tells whether the hash code has been computed. |
6004 inline bool HasHashCode(); | 6006 inline bool HasHashCode(); |
6005 | 6007 |
6006 // Returns a hash value used for the property table | 6008 // Returns a hash value used for the property table |
6007 inline uint32_t Hash(); | 6009 inline uint32_t Hash(); |
6008 | 6010 |
6009 static uint32_t ComputeHashField(unibrow::CharacterStream* buffer, | 6011 static uint32_t ComputeHashField(unibrow::CharacterStream* buffer, |
6010 int length); | 6012 int length, |
6013 uint32_t seed); | |
6011 | 6014 |
6012 static bool ComputeArrayIndex(unibrow::CharacterStream* buffer, | 6015 static bool ComputeArrayIndex(unibrow::CharacterStream* buffer, |
6013 uint32_t* index, | 6016 uint32_t* index, |
6014 int length); | 6017 int length); |
6015 | 6018 |
6016 // Externalization. | 6019 // Externalization. |
6017 bool MakeExternal(v8::String::ExternalStringResource* resource); | 6020 bool MakeExternal(v8::String::ExternalStringResource* resource); |
6018 bool MakeExternal(v8::String::ExternalAsciiStringResource* resource); | 6021 bool MakeExternal(v8::String::ExternalAsciiStringResource* resource); |
6019 | 6022 |
6020 // Conversion. | 6023 // Conversion. |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6065 // whether a hash code has been computed. If the hash code has been | 6068 // whether a hash code has been computed. If the hash code has been |
6066 // computed the 2nd bit tells whether the string can be used as an | 6069 // computed the 2nd bit tells whether the string can be used as an |
6067 // array index. | 6070 // array index. |
6068 static const int kHashNotComputedMask = 1; | 6071 static const int kHashNotComputedMask = 1; |
6069 static const int kIsNotArrayIndexMask = 1 << 1; | 6072 static const int kIsNotArrayIndexMask = 1 << 1; |
6070 static const int kNofHashBitFields = 2; | 6073 static const int kNofHashBitFields = 2; |
6071 | 6074 |
6072 // Shift constant retrieving hash code from hash field. | 6075 // Shift constant retrieving hash code from hash field. |
6073 static const int kHashShift = kNofHashBitFields; | 6076 static const int kHashShift = kNofHashBitFields; |
6074 | 6077 |
6078 // Only these bits are relevant in the hash, since the top two are shifted | |
6079 // out. | |
6080 static const uint32_t kHashBitMask = 0xffffffffu >> kHashShift; | |
Vyacheslav Egorov (Chromium)
2012/01/09 19:09:33
this constant is duplicated in every code generato
Erik Corry
2012/01/10 00:18:44
Yes, this should be fixed in bleeding edge.
| |
6081 | |
6075 // Array index strings this short can keep their index in the hash | 6082 // Array index strings this short can keep their index in the hash |
6076 // field. | 6083 // field. |
6077 static const int kMaxCachedArrayIndexLength = 7; | 6084 static const int kMaxCachedArrayIndexLength = 7; |
6078 | 6085 |
6079 // For strings which are array indexes the hash value has the string length | 6086 // For strings which are array indexes the hash value has the string length |
6080 // mixed into the hash, mainly to avoid a hash value of zero which would be | 6087 // mixed into the hash, mainly to avoid a hash value of zero which would be |
6081 // the case for the string '0'. 24 bits are used for the array index value. | 6088 // the case for the string '0'. 24 bits are used for the array index value. |
6082 static const int kArrayIndexValueBits = 24; | 6089 static const int kArrayIndexValueBits = 24; |
6083 static const int kArrayIndexLengthBits = | 6090 static const int kArrayIndexLengthBits = |
6084 kBitsPerInt - kArrayIndexValueBits - kNofHashBitFields; | 6091 kBitsPerInt - kArrayIndexValueBits - kNofHashBitFields; |
(...skipping 1401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7486 } else { | 7493 } else { |
7487 value &= ~(1 << bit_position); | 7494 value &= ~(1 << bit_position); |
7488 } | 7495 } |
7489 return value; | 7496 return value; |
7490 } | 7497 } |
7491 }; | 7498 }; |
7492 | 7499 |
7493 } } // namespace v8::internal | 7500 } } // namespace v8::internal |
7494 | 7501 |
7495 #endif // V8_OBJECTS_H_ | 7502 #endif // V8_OBJECTS_H_ |
OLD | NEW |