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

Side by Side Diff: src/harmony-templates.js

Issue 742643003: Cache template literal callSiteObj (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Ensure hash is a valid Smi literal Created 6 years 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 | « no previous file | src/parser.h » ('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 function GetTemplateCallSite(siteObj, rawStrings) { 7 var callSiteCache = new $Map;
8 // TODO(caitp): ensure same template callsite is used for subsequent tag calls 8
9 function SameCallSiteElements(rawStrings, other) {
10 var length = rawStrings.length;
11 var other = other.raw;
12
13 if (length !== other.length) return false;
14
15 for (var i = 0; i < length; ++i) {
16 if (rawStrings[i] !== other[i]) return false;
17 }
18
19 return true;
20 }
21
22
23 function GetCachedCallSite(siteObj, hash) {
24 var obj = %MapGet(callSiteCache, hash);
25
26 if (IS_UNDEFINED(obj)) return;
27
28 var length = obj.length;
29 for (var i = 0; i < length; ++i) {
30 if (SameCallSiteElements(siteObj, obj[i])) return obj[i];
31 }
32 }
33
34
35 function SetCachedCallSite(siteObj, hash) {
36 var obj = %MapGet(callSiteCache, hash);
37 var array;
38
39 if (IS_UNDEFINED(obj)) {
40 array = new InternalArray(1);
41 array[0] = siteObj;
42 %MapSet(callSiteCache, hash, array);
43 } else {
44 obj.push(siteObj);
45 }
46
47 return siteObj;
48 }
49
50
51 function GetTemplateCallSite(siteObj, rawStrings, hash) {
52 var cached = GetCachedCallSite(rawStrings, hash);
53
54 if (!IS_UNDEFINED(cached)) return cached;
9 55
10 %AddNamedProperty(siteObj, "raw", %ObjectFreeze(rawStrings), 56 %AddNamedProperty(siteObj, "raw", %ObjectFreeze(rawStrings),
11 READ_ONLY | DONT_ENUM | DONT_DELETE); 57 READ_ONLY | DONT_ENUM | DONT_DELETE);
12 58
13 return %ObjectFreeze(siteObj); 59 return SetCachedCallSite(%ObjectFreeze(siteObj), hash);
14 } 60 }
15 61
16 62
17 // ES6 Draft 10-14-2014, section 21.1.2.4 63 // ES6 Draft 10-14-2014, section 21.1.2.4
18 function StringRaw(callSite) { 64 function StringRaw(callSite) {
19 // TODO(caitp): Use rest parameters when implemented 65 // TODO(caitp): Use rest parameters when implemented
20 var numberOfSubstitutions = %_ArgumentsLength(); 66 var numberOfSubstitutions = %_ArgumentsLength();
21 var cooked = ToObject(callSite); 67 var cooked = ToObject(callSite);
22 var raw = ToObject(cooked.raw); 68 var raw = ToObject(cooked.raw);
23 var literalSegments = ToLength(raw.length); 69 var literalSegments = ToLength(raw.length);
(...skipping 15 matching lines...) Expand all
39 function ExtendStringForTemplates() { 85 function ExtendStringForTemplates() {
40 %CheckIsBootstrapping(); 86 %CheckIsBootstrapping();
41 87
42 // Set up the non-enumerable functions on the String object. 88 // Set up the non-enumerable functions on the String object.
43 InstallFunctions($String, DONT_ENUM, $Array( 89 InstallFunctions($String, DONT_ENUM, $Array(
44 "raw", StringRaw 90 "raw", StringRaw
45 )); 91 ));
46 } 92 }
47 93
48 ExtendStringForTemplates(); 94 ExtendStringForTemplates();
OLDNEW
« no previous file with comments | « no previous file | src/parser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698