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

Side by Side Diff: src/collection.js

Issue 1293493004: Unify symbols sharing across native scripts and runtime. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 4 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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 var $getHash; 5 var $getHash;
6 var $getExistingHash; 6 var $getExistingHash;
7 7
8 (function(global, utils) { 8 (function(global, utils) {
9 "use strict"; 9 "use strict";
10 10
11 %CheckIsBootstrapping(); 11 %CheckIsBootstrapping();
12 12
13 // ------------------------------------------------------------------- 13 // -------------------------------------------------------------------
14 // Imports 14 // Imports
15 15
16 var GlobalMap = global.Map; 16 var GlobalMap = global.Map;
17 var GlobalObject = global.Object; 17 var GlobalObject = global.Object;
18 var GlobalSet = global.Set; 18 var GlobalSet = global.Set;
19 var HashCodeSymbol = utils.GetPrivateSymbol("hash_code_symbol");
19 var IntRandom; 20 var IntRandom;
20 21
21 utils.Import(function(from) { 22 utils.Import(function(from) {
22 IntRandom = from.IntRandom; 23 IntRandom = from.IntRandom;
23 }); 24 });
24 25
25 var NumberIsNaN; 26 var NumberIsNaN;
26 27
27 utils.Import(function(from) { 28 utils.Import(function(from) {
28 NumberIsNaN = from.NumberIsNaN; 29 NumberIsNaN = from.NumberIsNaN;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 hash = ~hash + (hash << 15); // hash = (hash << 15) - hash - 1; 84 hash = ~hash + (hash << 15); // hash = (hash << 15) - hash - 1;
84 hash = hash ^ (hash >>> 12); 85 hash = hash ^ (hash >>> 12);
85 hash = hash + (hash << 2); 86 hash = hash + (hash << 2);
86 hash = hash ^ (hash >>> 4); 87 hash = hash ^ (hash >>> 4);
87 hash = (hash * 2057) | 0; // hash = (hash + (hash << 3)) + (hash << 11); 88 hash = (hash * 2057) | 0; // hash = (hash + (hash << 3)) + (hash << 11);
88 hash = hash ^ (hash >>> 16); 89 hash = hash ^ (hash >>> 16);
89 return hash & 0x3fffffff; 90 return hash & 0x3fffffff;
90 } 91 }
91 %SetForceInlineFlag(ComputeIntegerHash); 92 %SetForceInlineFlag(ComputeIntegerHash);
92 93
93 var hashCodeSymbol = GLOBAL_PRIVATE("hash_code_symbol");
94
95 function GetExistingHash(key) { 94 function GetExistingHash(key) {
96 if (%_IsSmi(key)) { 95 if (%_IsSmi(key)) {
97 return ComputeIntegerHash(key, 0); 96 return ComputeIntegerHash(key, 0);
98 } 97 }
99 if (IS_STRING(key)) { 98 if (IS_STRING(key)) {
100 var field = %_StringGetRawHashField(key); 99 var field = %_StringGetRawHashField(key);
101 if ((field & 1 /* Name::kHashNotComputedMask */) === 0) { 100 if ((field & 1 /* Name::kHashNotComputedMask */) === 0) {
102 return field >>> 2 /* Name::kHashShift */; 101 return field >>> 2 /* Name::kHashShift */;
103 } 102 }
104 } else if (IS_SPEC_OBJECT(key) && !%_IsJSProxy(key) && !IS_GLOBAL(key)) { 103 } else if (IS_SPEC_OBJECT(key) && !%_IsJSProxy(key) && !IS_GLOBAL(key)) {
105 var hash = GET_PRIVATE(key, hashCodeSymbol); 104 var hash = GET_PRIVATE(key, HashCodeSymbol);
106 return hash; 105 return hash;
107 } 106 }
108 return %GenericHash(key); 107 return %GenericHash(key);
109 } 108 }
110 %SetForceInlineFlag(GetExistingHash); 109 %SetForceInlineFlag(GetExistingHash);
111 110
112 111
113 function GetHash(key) { 112 function GetHash(key) {
114 var hash = GetExistingHash(key); 113 var hash = GetExistingHash(key);
115 if (IS_UNDEFINED(hash)) { 114 if (IS_UNDEFINED(hash)) {
116 hash = IntRandom() | 0; 115 hash = IntRandom() | 0;
117 if (hash === 0) hash = 1; 116 if (hash === 0) hash = 1;
118 SET_PRIVATE(key, hashCodeSymbol, hash); 117 SET_PRIVATE(key, HashCodeSymbol, hash);
119 } 118 }
120 return hash; 119 return hash;
121 } 120 }
122 %SetForceInlineFlag(GetHash); 121 %SetForceInlineFlag(GetHash);
123 122
124 123
125 // ------------------------------------------------------------------- 124 // -------------------------------------------------------------------
126 // Harmony Set 125 // Harmony Set
127 126
128 function SetConstructor(iterable) { 127 function SetConstructor(iterable) {
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 to.MapHas = MapHas; 508 to.MapHas = MapHas;
510 to.MapDelete = MapDelete; 509 to.MapDelete = MapDelete;
511 to.SetAdd = SetAdd; 510 to.SetAdd = SetAdd;
512 to.SetHas = SetHas; 511 to.SetHas = SetHas;
513 to.SetDelete = SetDelete; 512 to.SetDelete = SetDelete;
514 to.MapFromArray = MapFromArray; 513 to.MapFromArray = MapFromArray;
515 to.SetFromArray = SetFromArray; 514 to.SetFromArray = SetFromArray;
516 }); 515 });
517 516
518 }) 517 })
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698