mirror of
https://github.com/Polymer/polymer.git
synced 2026-08-19 01:14:44 -05:00
Use values.reduce instead of a temporary array
Seems to be faster in v8
This commit is contained in:
@@ -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;
|
||||
};
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user