From be9d6210f0245c0ec9a4d34775c48419c32c29a4 Mon Sep 17 00:00:00 2001 From: Daniel Freedman Date: Mon, 4 Dec 2017 17:41:54 -0800 Subject: [PATCH] Use values.reduce instead of a temporary array Seems to be faster in v8 --- lib/utils/html-fn.html | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/utils/html-fn.html b/lib/utils/html-fn.html index 72b2c824f0..fccc70bcc6 100644 --- a/lib/utils/html-fn.html +++ b/lib/utils/html-fn.html @@ -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} */ - 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; }; })();