From c95c50967480063be2ecb725b87d2ae59f34af5e Mon Sep 17 00:00:00 2001 From: Bart Veneman Date: Fri, 20 Oct 2023 09:24:38 +0200 Subject: [PATCH] perf: avoid *a lot* of property lookups while analyzing specificity --- src/index.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/index.js b/src/index.js index a20a7ed..f64b9fb 100644 --- a/src/index.js +++ b/src/index.js @@ -270,10 +270,18 @@ export function analyze(css, options = {}) { // #region specificity let [{ value: specificityObj }] = calculate(node) + let sa = specificityObj.a + let sb = specificityObj.b + let sc = specificityObj.c + /** @type {Specificity} */ - let specificity = [specificityObj.a, specificityObj.b, specificityObj.c] + let specificity = [sa, sb, sc] + + uniqueSpecificities.push(sa + ',' + sb + ',' + sc, node.loc) - uniqueSpecificities.push(specificity[0] + ',' + specificity[1] + ',' + specificity[2], node.loc) + specificityA.push(sa) + specificityB.push(sb) + specificityC.push(sc) if (maxSpecificity === undefined) { maxSpecificity = specificity @@ -283,10 +291,6 @@ export function analyze(css, options = {}) { minSpecificity = specificity } - specificityA.push(specificity[0]) - specificityB.push(specificity[1]) - specificityC.push(specificity[2]) - if (minSpecificity !== undefined && compareSpecificity(minSpecificity, specificity) < 0) { minSpecificity = specificity } @@ -298,7 +302,7 @@ export function analyze(css, options = {}) { specificities.push(specificity) // #endregion - if (specificity[0] > 0) { + if (sa > 0) { ids.push(selector, node.loc) }