From fbdd413fb408f9a90557c524639bda135de0742b Mon Sep 17 00:00:00 2001 From: Anton Kudryavtsev Date: Fri, 13 Mar 2020 20:06:17 +0300 Subject: [PATCH] perf(styles): small CSS injector optimization do not search for id when it is not required --- src/runtime/inject-css.js | 3 +- test/__snapshots__/index.test.ts.snap | 54 ++++++++++++++++++--------- 2 files changed, 38 insertions(+), 19 deletions(-) diff --git a/src/runtime/inject-css.js b/src/runtime/inject-css.js index 6b8cc267..c01f2222 100644 --- a/src/runtime/inject-css.js +++ b/src/runtime/inject-css.js @@ -31,9 +31,10 @@ export default (css, options = {}) => { /** @type {HTMLStyleElement} */ let styleTag; - let id = containers.indexOf(container); if (singleTag) { + let id = containers.indexOf(container); + if (id === -1) { id = containers.push(container) - 1; styleTags[id] = {}; diff --git a/test/__snapshots__/index.test.ts.snap b/test/__snapshots__/index.test.ts.snap index 3074d818..8d2b411e 100644 --- a/test/__snapshots__/index.test.ts.snap +++ b/test/__snapshots__/index.test.ts.snap @@ -36,9 +36,10 @@ var injector_14187a73 = (css, options = {}) => { /** @type {HTMLStyleElement} */ let styleTag; - let id = containers.indexOf(container); if (singleTag) { + let id = containers.indexOf(container); + if (id === -1) { id = containers.push(container) - 1; styleTags[id] = {}; @@ -106,9 +107,10 @@ var injector_14187a73 = (css, options = {}) => { /** @type {HTMLStyleElement} */ let styleTag; - let id = containers.indexOf(container); if (singleTag) { + let id = containers.indexOf(container); + if (id === -1) { id = containers.push(container) - 1; styleTags[id] = {}; @@ -197,9 +199,10 @@ var injector_14187a73 = (css, options = {}) => { /** @type {HTMLStyleElement} */ let styleTag; - let id = containers.indexOf(container); if (singleTag) { + let id = containers.indexOf(container); + if (id === -1) { id = containers.push(container) - 1; styleTags[id] = {}; @@ -284,9 +287,10 @@ var injector_14187a73 = (css, options = {}) => { /** @type {HTMLStyleElement} */ let styleTag; - let id = containers.indexOf(container); if (singleTag) { + let id = containers.indexOf(container); + if (id === -1) { id = containers.push(container) - 1; styleTags[id] = {}; @@ -537,9 +541,10 @@ var injector_14187a73 = (css, options = {}) => { /** @type {HTMLStyleElement} */ let styleTag; - let id = containers.indexOf(container); if (singleTag) { + let id = containers.indexOf(container); + if (id === -1) { id = containers.push(container) - 1; styleTags[id] = {}; @@ -659,9 +664,10 @@ var injector_14187a73 = (css, options = {}) => { /** @type {HTMLStyleElement} */ let styleTag; - let id = containers.indexOf(container); if (singleTag) { + let id = containers.indexOf(container); + if (id === -1) { id = containers.push(container) - 1; styleTags[id] = {}; @@ -746,9 +752,10 @@ var injector_14187a73 = (css, options = {}) => { /** @type {HTMLStyleElement} */ let styleTag; - let id = containers.indexOf(container); if (singleTag) { + let id = containers.indexOf(container); + if (id === -1) { id = containers.push(container) - 1; styleTags[id] = {}; @@ -984,9 +991,10 @@ var injector_14187a73 = (css, options = {}) => { /** @type {HTMLStyleElement} */ let styleTag; - let id = containers.indexOf(container); if (singleTag) { + let id = containers.indexOf(container); + if (id === -1) { id = containers.push(container) - 1; styleTags[id] = {}; @@ -1065,9 +1073,10 @@ var injector_14187a73 = (css, options = {}) => { /** @type {HTMLStyleElement} */ let styleTag; - let id = containers.indexOf(container); if (singleTag) { + let id = containers.indexOf(container); + if (id === -1) { id = containers.push(container) - 1; styleTags[id] = {}; @@ -1146,9 +1155,10 @@ var injector_14187a73 = (css, options = {}) => { /** @type {HTMLStyleElement} */ let styleTag; - let id = containers.indexOf(container); if (singleTag) { + let id = containers.indexOf(container); + if (id === -1) { id = containers.push(container) - 1; styleTags[id] = {}; @@ -1230,9 +1240,10 @@ var injector_14187a73 = (css, options = {}) => { /** @type {HTMLStyleElement} */ let styleTag; - let id = containers.indexOf(container); if (singleTag) { + let id = containers.indexOf(container); + if (id === -1) { id = containers.push(container) - 1; styleTags[id] = {}; @@ -1321,9 +1332,10 @@ var injector_14187a73 = (css, options = {}) => { /** @type {HTMLStyleElement} */ let styleTag; - let id = containers.indexOf(container); if (singleTag) { + let id = containers.indexOf(container); + if (id === -1) { id = containers.push(container) - 1; styleTags[id] = {}; @@ -1391,9 +1403,10 @@ var injector_14187a73 = (css, options = {}) => { /** @type {HTMLStyleElement} */ let styleTag; - let id = containers.indexOf(container); if (singleTag) { + let id = containers.indexOf(container); + if (id === -1) { id = containers.push(container) - 1; styleTags[id] = {}; @@ -1461,9 +1474,10 @@ var injector_14187a73 = (css, options = {}) => { /** @type {HTMLStyleElement} */ let styleTag; - let id = containers.indexOf(container); if (singleTag) { + let id = containers.indexOf(container); + if (id === -1) { id = containers.push(container) - 1; styleTags[id] = {}; @@ -1531,9 +1545,10 @@ var injector_14187a73 = (css, options = {}) => { /** @type {HTMLStyleElement} */ let styleTag; - let id = containers.indexOf(container); if (singleTag) { + let id = containers.indexOf(container); + if (id === -1) { id = containers.push(container) - 1; styleTags[id] = {}; @@ -1604,9 +1619,10 @@ var injector_14187a73 = (css, options = {}) => { /** @type {HTMLStyleElement} */ let styleTag; - let id = containers.indexOf(container); if (singleTag) { + let id = containers.indexOf(container); + if (id === -1) { id = containers.push(container) - 1; styleTags[id] = {}; @@ -1674,9 +1690,10 @@ var injector_14187a73 = (css, options = {}) => { /** @type {HTMLStyleElement} */ let styleTag; - let id = containers.indexOf(container); if (singleTag) { + let id = containers.indexOf(container); + if (id === -1) { id = containers.push(container) - 1; styleTags[id] = {}; @@ -1761,9 +1778,10 @@ var injector_14187a73 = (css, options = {}) => { /** @type {HTMLStyleElement} */ let styleTag; - let id = containers.indexOf(container); if (singleTag) { + let id = containers.indexOf(container); + if (id === -1) { id = containers.push(container) - 1; styleTags[id] = {};