| 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);
|
| }
|
|
|
|
|
|
|