Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(229)

Side by Side Diff: src/objects-inl.h

Issue 6525: Calculate string hash during flattening. (Closed)
Patch Set: Created 12 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 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 2070 matching lines...) Expand 10 before | Expand all | Expand 10 after
2081 2081
2082 uint32_t String::Hash() { 2082 uint32_t String::Hash() {
2083 // Fast case: has hash code already been computed? 2083 // Fast case: has hash code already been computed?
2084 uint32_t field = length_field(); 2084 uint32_t field = length_field();
2085 if (field & kHashComputedMask) return field >> kHashShift; 2085 if (field & kHashComputedMask) return field >> kHashShift;
2086 // Slow case: compute hash code and set it.. 2086 // Slow case: compute hash code and set it..
2087 return ComputeAndSetHash(); 2087 return ComputeAndSetHash();
2088 } 2088 }
2089 2089
2090 2090
2091 StringHasher::StringHasher(int length)
2092 : length_(length),
2093 raw_running_hash_(0),
2094 array_index_(0),
2095 is_array_index_(0 < length_ && length_ <= String::kMaxArrayIndexSize),
2096 is_first_char_(true),
2097 is_valid_(true) { }
2098
2099
2100 bool StringHasher::has_trivial_hash() {
2101 return length_ > String::kMaxMediumStringSize;
2102 }
2103
2104
2105 void StringHasher::AddCharacter(uc32 c) {
2106 // Note: the Jenkins one-at-a-time hash function
2107 raw_running_hash_ += c;
2108 raw_running_hash_ += (raw_running_hash_ << 10);
2109 raw_running_hash_ ^= (raw_running_hash_ >> 6);
2110 // Incremental array index computation
2111 if (is_array_index_) {
2112 if (c < '0' || c > '9') {
2113 is_array_index_ = false;
2114 } else {
2115 int d = c - '0';
2116 if (is_first_char_) {
2117 is_first_char_ = false;
2118 if (c == '0' && length_ > 1) {
2119 is_array_index_ = false;
2120 return;
2121 }
2122 }
2123 if (array_index_ > 429496729U - ((d > 5) ? 1 : 0)) {
Erik Corry 2008/10/07 10:04:34 (d + 2) >> 3 will probably avoid an unpredictable
2124 is_array_index_ = false;
2125 } else {
2126 array_index_ = array_index_ * 10 + d;
2127 }
2128 }
2129 }
2130 }
2131
2132
2133 void StringHasher::AddCharacterNoIndex(uc32 c) {
2134 ASSERT(!is_array_index());
2135 raw_running_hash_ += c;
2136 raw_running_hash_ += (raw_running_hash_ << 10);
2137 raw_running_hash_ ^= (raw_running_hash_ >> 6);
2138 }
2139
2140
2141 uint32_t StringHasher::GetHash() {
2142 uint32_t result = raw_running_hash_;
2143 result += (result << 3);
2144 result ^= (result >> 11);
2145 result += (result << 15);
2146 return result;
2147 }
2148
2149
2091 bool String::AsArrayIndex(uint32_t* index) { 2150 bool String::AsArrayIndex(uint32_t* index) {
2092 uint32_t field = length_field(); 2151 uint32_t field = length_field();
2093 if ((field & kHashComputedMask) && !(field & kIsArrayIndexMask)) return false; 2152 if ((field & kHashComputedMask) && !(field & kIsArrayIndexMask)) return false;
2094 return SlowAsArrayIndex(index); 2153 return SlowAsArrayIndex(index);
2095 } 2154 }
2096 2155
2097 2156
2098 Object* JSObject::GetPrototype() { 2157 Object* JSObject::GetPrototype() {
2099 return JSObject::cast(this)->map()->prototype(); 2158 return JSObject::cast(this)->map()->prototype();
2100 } 2159 }
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
2179 #undef WRITE_INT_FIELD 2238 #undef WRITE_INT_FIELD
2180 #undef READ_SHORT_FIELD 2239 #undef READ_SHORT_FIELD
2181 #undef WRITE_SHORT_FIELD 2240 #undef WRITE_SHORT_FIELD
2182 #undef READ_BYTE_FIELD 2241 #undef READ_BYTE_FIELD
2183 #undef WRITE_BYTE_FIELD 2242 #undef WRITE_BYTE_FIELD
2184 2243
2185 2244
2186 } } // namespace v8::internal 2245 } } // namespace v8::internal
2187 2246
2188 #endif // V8_OBJECTS_INL_H_ 2247 #endif // V8_OBJECTS_INL_H_
OLDNEW
« src/objects.cc ('K') | « src/objects.cc ('k') | src/runtime.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698