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 4174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4185 | 4185 |
4186 // Minimum length for a cons string. | 4186 // Minimum length for a cons string. |
4187 static const int kMinNonFlatLength = 13; | 4187 static const int kMinNonFlatLength = 13; |
4188 | 4188 |
4189 // Mask constant for checking if a string has a computed hash code | 4189 // Mask constant for checking if a string has a computed hash code |
4190 // and if it is an array index. The least significant bit indicates | 4190 // and if it is an array index. The least significant bit indicates |
4191 // whether a hash code has been computed. If the hash code has been | 4191 // whether a hash code has been computed. If the hash code has been |
4192 // computed the 2nd bit tells whether the string can be used as an | 4192 // computed the 2nd bit tells whether the string can be used as an |
4193 // array index. | 4193 // array index. |
4194 static const int kHashNotComputedMask = 1; | 4194 static const int kHashNotComputedMask = 1; |
4195 static const int kIsArrayIndexMask = 1 << 1; | 4195 static const int kIsNotArrayIndexMask = 1 << 1; |
4196 static const int kNofLengthBitFields = 2; | 4196 static const int kNofHashBitFields = 2; |
4197 | 4197 |
4198 // Shift constant retrieving hash code from hash field. | 4198 // Shift constant retrieving hash code from hash field. |
4199 static const int kHashShift = kNofLengthBitFields; | 4199 static const int kHashShift = kNofHashBitFields; |
4200 | 4200 |
4201 // Array index strings this short can keep their index in the hash | 4201 // Array index strings this short can keep their index in the hash |
4202 // field. | 4202 // field. |
4203 static const int kMaxCachedArrayIndexLength = 7; | 4203 static const int kMaxCachedArrayIndexLength = 7; |
4204 | 4204 |
4205 // For strings which are array indexes the hash value has the string length | 4205 // For strings which are array indexes the hash value has the string length |
4206 // mixed into the hash, mainly to avoid a hash value of zero which would be | 4206 // mixed into the hash, mainly to avoid a hash value of zero which would be |
4207 // the case for the string '0'. 24 bits are used for the array index value. | 4207 // the case for the string '0'. 24 bits are used for the array index value. |
4208 static const int kArrayIndexHashLengthShift = 24 + kNofLengthBitFields; | 4208 static const int kArrayIndexValueBits = 24; |
4209 static const int kArrayIndexLengthBits = | |
4210 kBitsPerInt - kArrayIndexValueBits - kNofHashBitFields; | |
Lasse Reichstein
2010/06/07 09:34:04
You want kSmiValueSize, not kBitsPerInt, here.
| |
4211 | |
4212 STATIC_CHECK((kArrayIndexLengthBits > 0)); | |
4213 | |
4214 static const int kArrayIndexHashLengthShift = | |
4215 kArrayIndexValueBits + kNofHashBitFields; | |
4216 | |
4209 static const int kArrayIndexHashMask = (1 << kArrayIndexHashLengthShift) - 1; | 4217 static const int kArrayIndexHashMask = (1 << kArrayIndexHashLengthShift) - 1; |
4210 static const int kArrayIndexValueBits = | 4218 |
4211 kArrayIndexHashLengthShift - kHashShift; | |
4212 static const int kArrayIndexValueMask = | 4219 static const int kArrayIndexValueMask = |
4213 ((1 << kArrayIndexValueBits) - 1) << kHashShift; | 4220 ((1 << kArrayIndexValueBits) - 1) << kHashShift; |
4214 | 4221 |
4222 // Check that kMaxCachedArrayIndexLength + 1 is a power of two so we | |
4223 // could use a mask to test if the length of string is less than or equal to | |
4224 // kMaxCachedArrayIndexLength. | |
4225 STATIC_CHECK(IS_POWER_OF_TWO(kMaxCachedArrayIndexLength + 1)); | |
4226 | |
4227 static const int kContainsCachedArrayIndexMask = | |
4228 (~kMaxCachedArrayIndexLength << kArrayIndexHashLengthShift) | | |
4229 kIsNotArrayIndexMask; | |
4230 | |
4215 // Value of empty hash field indicating that the hash is not computed. | 4231 // Value of empty hash field indicating that the hash is not computed. |
4216 static const int kEmptyHashField = kHashNotComputedMask; | 4232 static const int kEmptyHashField = |
4233 kIsNotArrayIndexMask | kHashNotComputedMask; | |
4217 | 4234 |
4218 // Value of hash field containing computed hash equal to zero. | 4235 // Value of hash field containing computed hash equal to zero. |
4219 static const int kZeroHash = 0; | 4236 static const int kZeroHash = kIsNotArrayIndexMask; |
4220 | 4237 |
4221 // Maximal string length. | 4238 // Maximal string length. |
4222 static const int kMaxLength = (1 << (32 - 2)) - 1; | 4239 static const int kMaxLength = (1 << (32 - 2)) - 1; |
4223 | 4240 |
4224 // Max length for computing hash. For strings longer than this limit the | 4241 // Max length for computing hash. For strings longer than this limit the |
4225 // string length is used as the hash value. | 4242 // string length is used as the hash value. |
4226 static const int kMaxHashCalcLength = 16383; | 4243 static const int kMaxHashCalcLength = 16383; |
4227 | 4244 |
4228 // Limit for truncation in short printing. | 4245 // Limit for truncation in short printing. |
4229 static const int kMaxShortPrintLength = 1024; | 4246 static const int kMaxShortPrintLength = 1024; |
(...skipping 1022 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5252 } else { | 5269 } else { |
5253 value &= ~(1 << bit_position); | 5270 value &= ~(1 << bit_position); |
5254 } | 5271 } |
5255 return value; | 5272 return value; |
5256 } | 5273 } |
5257 }; | 5274 }; |
5258 | 5275 |
5259 } } // namespace v8::internal | 5276 } } // namespace v8::internal |
5260 | 5277 |
5261 #endif // V8_OBJECTS_H_ | 5278 #endif // V8_OBJECTS_H_ |
OLD | NEW |