Use values.reduce instead of a temporary array

Seems to be faster in v8
This commit is contained in:
Daniel Freedman
2017-12-04 17:41:54 -08:00
parent 530a68b44a
commit be9d6210f0
+2 -6
View File
@@ -54,13 +54,9 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
Polymer.html = function html(strings, ...values) {
// use raw strings to preserve literal escapes in strings
const rawStrings = strings.raw;
/** @type {!Array<string>} */
const parts = [rawStrings[0]];
const template = /** @type {!HTMLTemplateElement} */(document.createElement('template'));
for (let i = 0; i < values.length; i++) {
parts.push(htmlValue(values[i]), rawStrings[i + 1]);
}
template.innerHTML = parts.join('');
template.innerHTML = values.reduce((acc, v, idx) =>
acc + htmlValue(v) + rawStrings[idx + 1], rawStrings[0]);
return template;
};
})();