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

Side by Side Diff: src/utils.h

Issue 9190001: Backport @10366 to 3.6 Base URL: http://v8.googlecode.com/svn/branches/3.6/
Patch Set: '' Created 8 years, 11 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 | Annotate | Revision Log
OLDNEW
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 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 // Extracts the bit field from the value. 230 // Extracts the bit field from the value.
231 static T decode(uint32_t value) { 231 static T decode(uint32_t value) {
232 return static_cast<T>((value & kMask) >> shift); 232 return static_cast<T>((value & kMask) >> shift);
233 } 233 }
234 }; 234 };
235 235
236 236
237 // ---------------------------------------------------------------------------- 237 // ----------------------------------------------------------------------------
238 // Hash function. 238 // Hash function.
239 239
240 static const uint32_t kZeroHashSeed = 0;
241
240 // Thomas Wang, Integer Hash Functions. 242 // Thomas Wang, Integer Hash Functions.
241 // http://www.concentric.net/~Ttwang/tech/inthash.htm 243 // http://www.concentric.net/~Ttwang/tech/inthash.htm
242 static inline uint32_t ComputeIntegerHash(uint32_t key) { 244 static inline uint32_t ComputeIntegerHash(uint32_t key, uint32_t seed) {
243 uint32_t hash = key; 245 uint32_t hash = key;
246 hash = hash ^ seed;
244 hash = ~hash + (hash << 15); // hash = (hash << 15) - hash - 1; 247 hash = ~hash + (hash << 15); // hash = (hash << 15) - hash - 1;
245 hash = hash ^ (hash >> 12); 248 hash = hash ^ (hash >> 12);
246 hash = hash + (hash << 2); 249 hash = hash + (hash << 2);
247 hash = hash ^ (hash >> 4); 250 hash = hash ^ (hash >> 4);
248 hash = hash * 2057; // hash = (hash + (hash << 3)) + (hash << 11); 251 hash = hash * 2057; // hash = (hash + (hash << 3)) + (hash << 11);
249 hash = hash ^ (hash >> 16); 252 hash = hash ^ (hash >> 16);
250 return hash; 253 return hash;
251 } 254 }
252 255
253 256
254 static inline uint32_t ComputePointerHash(void* ptr) { 257 static inline uint32_t ComputePointerHash(void* ptr) {
255 return ComputeIntegerHash( 258 return ComputeIntegerHash(
256 static_cast<uint32_t>(reinterpret_cast<intptr_t>(ptr))); 259 static_cast<uint32_t>(reinterpret_cast<intptr_t>(ptr)),
260 v8::internal::kZeroHashSeed);
257 } 261 }
258 262
259 263
260 // ---------------------------------------------------------------------------- 264 // ----------------------------------------------------------------------------
261 // Miscellaneous 265 // Miscellaneous
262 266
263 // A static resource holds a static instance that can be reserved in 267 // A static resource holds a static instance that can be reserved in
264 // a local scope using an instance of Access. Attempts to re-reserve 268 // a local scope using an instance of Access. Attempts to re-reserve
265 // the instance will cause an error. 269 // the instance will cause an error.
266 template <typename T> 270 template <typename T>
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after
911 ASSERT(element < static_cast<int>(sizeof(T) * CHAR_BIT)); 915 ASSERT(element < static_cast<int>(sizeof(T) * CHAR_BIT));
912 return 1 << element; 916 return 1 << element;
913 } 917 }
914 918
915 T bits_; 919 T bits_;
916 }; 920 };
917 921
918 } } // namespace v8::internal 922 } } // namespace v8::internal
919 923
920 #endif // V8_UTILS_H_ 924 #endif // V8_UTILS_H_
OLDNEW
« src/objects.h ('K') | « src/type-info.cc ('k') | src/v8globals.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698