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

Unified 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, 1 month 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/parser.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/harmony-templates.js
diff --git a/src/harmony-templates.js b/src/harmony-templates.js
index 712d8d3a12bbb996d1bd838c09d81fd9d180e3e6..41ce838aa18cd2b63b0cf20870ac240b191688ba 100644
--- a/src/harmony-templates.js
+++ b/src/harmony-templates.js
@@ -4,13 +4,59 @@
'use strict';
-function GetTemplateCallSite(siteObj, rawStrings) {
- // TODO(caitp): ensure same template callsite is used for subsequent tag calls
+var callSiteCache = new $Map;
+
+function SameCallSiteElements(rawStrings, other) {
+ var length = rawStrings.length;
+ var other = other.raw;
+
+ if (length !== other.length) return false;
+
+ for (var i = 0; i < length; ++i) {
+ if (rawStrings[i] !== other[i]) return false;
+ }
+
+ return true;
+}
+
+
+function GetCachedCallSite(siteObj, hash) {
+ var obj = %MapGet(callSiteCache, hash);
+
+ if (IS_UNDEFINED(obj)) return;
+
+ var length = obj.length;
+ for (var i = 0; i < length; ++i) {
+ if (SameCallSiteElements(siteObj, obj[i])) return obj[i];
+ }
+}
+
+
+function SetCachedCallSite(siteObj, hash) {
+ var obj = %MapGet(callSiteCache, hash);
+ var array;
+
+ if (IS_UNDEFINED(obj)) {
+ array = new InternalArray(1);
+ array[0] = siteObj;
+ %MapSet(callSiteCache, hash, array);
+ } else {
+ obj.push(siteObj);
+ }
+
+ return siteObj;
+}
+
+
+function GetTemplateCallSite(siteObj, rawStrings, hash) {
+ var cached = GetCachedCallSite(rawStrings, hash);
+
+ if (!IS_UNDEFINED(cached)) return cached;
%AddNamedProperty(siteObj, "raw", %ObjectFreeze(rawStrings),
READ_ONLY | DONT_ENUM | DONT_DELETE);
- return %ObjectFreeze(siteObj);
+ return SetCachedCallSite(%ObjectFreeze(siteObj), hash);
}
« 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