Skip to content

Commit

Permalink
Use values.reduce instead of a temporary array
Browse files Browse the repository at this point in the history
Seems to be faster in v8
  • Loading branch information
dfreedm committed Dec 5, 2017
1 parent 530a68b commit be9d621
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions lib/utils/html-fn.html
Expand Up @@ -54,13 +54,9 @@
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;
};
})();
Expand Down

0 comments on commit be9d621

Please sign in to comment.