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

Side by Side Diff: src/templates.js

Issue 947683002: Reimplement Maps and Sets in JS (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Merged to master Created 5 years, 8 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
« no previous file with comments | « src/runtime/runtime-collections.cc ('k') | src/x64/code-stubs-x64.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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 "use strict"; 5 "use strict";
6 6
7 var callSiteCache = new $Map; 7 var callSiteCache = new $Map;
8 8
9 function SameCallSiteElements(rawStrings, other) { 9 function SameCallSiteElements(rawStrings, other) {
10 var length = rawStrings.length; 10 var length = rawStrings.length;
11 var other = other.raw; 11 var other = other.raw;
12 12
13 if (length !== other.length) return false; 13 if (length !== other.length) return false;
14 14
15 for (var i = 0; i < length; ++i) { 15 for (var i = 0; i < length; ++i) {
16 if (rawStrings[i] !== other[i]) return false; 16 if (rawStrings[i] !== other[i]) return false;
17 } 17 }
18 18
19 return true; 19 return true;
20 } 20 }
21 21
22 22
23 function GetCachedCallSite(siteObj, hash) { 23 function GetCachedCallSite(siteObj, hash) {
24 var obj = %MapGet(callSiteCache, hash); 24 var obj = %_CallFunction(callSiteCache, hash, $MapGet);
25 25
26 if (IS_UNDEFINED(obj)) return; 26 if (IS_UNDEFINED(obj)) return;
27 27
28 var length = obj.length; 28 var length = obj.length;
29 for (var i = 0; i < length; ++i) { 29 for (var i = 0; i < length; ++i) {
30 if (SameCallSiteElements(siteObj, obj[i])) return obj[i]; 30 if (SameCallSiteElements(siteObj, obj[i])) return obj[i];
31 } 31 }
32 } 32 }
33 33
34 34
35 function SetCachedCallSite(siteObj, hash) { 35 function SetCachedCallSite(siteObj, hash) {
36 var obj = %MapGet(callSiteCache, hash); 36 var obj = %_CallFunction(callSiteCache, hash, $MapGet);
37 var array; 37 var array;
38 38
39 if (IS_UNDEFINED(obj)) { 39 if (IS_UNDEFINED(obj)) {
40 array = new InternalArray(1); 40 array = new InternalArray(1);
41 array[0] = siteObj; 41 array[0] = siteObj;
42 %MapSet(callSiteCache, hash, array); 42 %_CallFunction(callSiteCache, hash, array, $MapSet);
43 } else { 43 } else {
44 obj.push(siteObj); 44 obj.push(siteObj);
45 } 45 }
46 46
47 return siteObj; 47 return siteObj;
48 } 48 }
49 49
50 50
51 function GetTemplateCallSite(siteObj, rawStrings, hash) { 51 function GetTemplateCallSite(siteObj, rawStrings, hash) {
52 var cached = GetCachedCallSite(rawStrings, hash); 52 var cached = GetCachedCallSite(rawStrings, hash);
53 53
54 if (!IS_UNDEFINED(cached)) return cached; 54 if (!IS_UNDEFINED(cached)) return cached;
55 55
56 %AddNamedProperty(siteObj, "raw", %ObjectFreeze(rawStrings), 56 %AddNamedProperty(siteObj, "raw", %ObjectFreeze(rawStrings),
57 READ_ONLY | DONT_ENUM | DONT_DELETE); 57 READ_ONLY | DONT_ENUM | DONT_DELETE);
58 58
59 return SetCachedCallSite(%ObjectFreeze(siteObj), hash); 59 return SetCachedCallSite(%ObjectFreeze(siteObj), hash);
60 } 60 }
OLDNEW
« no previous file with comments | « src/runtime/runtime-collections.cc ('k') | src/x64/code-stubs-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698