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

Unified Diff: src/collection.js

Issue 1157073002: Speed up object-keyed Map and Set by giving out sequential hash codes Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Revert inadvertent change Created 5 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/math.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/collection.js
diff --git a/src/collection.js b/src/collection.js
index 6b468f5fc0ee8b2de8cd61ca1a27e4c78c8dcfb5..1cc6857b3c4330c2782b6856c8bb9e471e9be8f7 100644
--- a/src/collection.js
+++ b/src/collection.js
@@ -16,11 +16,6 @@ var $getExistingHash;
var GlobalMap = global.Map;
var GlobalObject = global.Object;
var GlobalSet = global.Set;
-var IntRandom;
-
-utils.Import(function(from) {
- IntRandom = from.IntRandom;
-});
var NumberIsNaN;
@@ -110,11 +105,16 @@ function GetExistingHash(key) {
%SetForceInlineFlag(GetExistingHash);
+var hashCounter = 1;
+
+
function GetHash(key) {
var hash = GetExistingHash(key);
if (IS_UNDEFINED(hash)) {
- hash = IntRandom() | 0;
- if (hash === 0) hash = 1;
+ hash = hashCounter;
+ // Avoid a hash of zero, reserved for the hidden string. Also avoid
+ // non-Smi hashes.
+ hashCounter = hash == 0x3fffffff ? 1 : hash + 1;
SET_PRIVATE(key, hashCodeSymbol, hash);
}
return hash;
« no previous file with comments | « no previous file | src/math.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698