diff --git a/src/display/text_layer.js b/src/display/text_layer.js index cdac05ad5..1bd06bfd5 100644 --- a/src/display/text_layer.js +++ b/src/display/text_layer.js @@ -48,11 +48,6 @@ var renderTextLayer = (function renderTextLayerClosure() { return !NonWhitespaceRegexp.test(str); } - // Text layers may contain many thousands of divs, and using `styleBuf` avoids - // creating many intermediate strings when building their 'style' properties. - var styleBuf = ['left: ', 0, 'px; top: ', 0, 'px; font-size: ', 0, - 'px; font-family: ', '', ';']; - function appendText(task, geom, styles) { // Initialize all used properties to keep the caches monomorphic. var textDiv = document.createElement('span'); @@ -97,11 +92,12 @@ var renderTextLayer = (function renderTextLayerClosure() { left = tx[4] + (fontAscent * Math.sin(angle)); top = tx[5] - (fontAscent * Math.cos(angle)); } - styleBuf[1] = left; - styleBuf[3] = top; - styleBuf[5] = fontHeight; - styleBuf[7] = style.fontFamily; - textDiv.setAttribute('style', styleBuf.join('')); + // Setting the style properties individually, rather than all at once, + // should be OK since the `textDiv` isn't appended to the document yet. + textDiv.style.left = `${left}px`; + textDiv.style.top = `${top}px`; + textDiv.style.fontSize = `${fontHeight}px`; + textDiv.style.fontFamily = style.fontFamily; textDiv.textContent = geom.str; // `fontName` is only used by the FontInspector, and we only use `dataset`