Skip to content

Commit

Permalink
perf: avoid *a lot* of property lookups while analyzing specificity
Browse files Browse the repository at this point in the history
  • Loading branch information
Bart Veneman committed Oct 20, 2023
1 parent 1e3b8bc commit c95c509
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand All @@ -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)
}

Expand Down

0 comments on commit c95c509

Please sign in to comment.