Skip to content

Commit 88888fd

Browse files
RobinMalfaitadamwathan
authored andcommitted
switch to a do {} while ()
We alreayd know that we have an `@apply` otherwise we would not have called that function in the first place. Moving to a `do {} while ()` allows us to skip 1 call to `hasAtRule(css, 'apply')`. Which is nice because that skips a possible full traversal.
1 parent f2e3e22 commit 88888fd

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/flagged/applyComplexClasses.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ function makeExtractUtilityRules(css, config) {
173173
function processApplyAtRules(css, lookupTree, config) {
174174
const extractUtilityRules = makeExtractUtilityRules(lookupTree, config)
175175

176-
while (hasAtRule(css, 'apply')) {
176+
do {
177177
css.walkRules(rule => {
178178
const applyRules = []
179179

@@ -232,7 +232,18 @@ function processApplyAtRules(css, lookupTree, config) {
232232
rule.remove()
233233
}
234234
})
235-
}
235+
236+
// We already know that we have at least 1 @apply rule. Otherwise this
237+
// function would not have been called. Therefore we can execute this code
238+
// at least once. This also means that in the best case scenario we only
239+
// call this 2 times, instead of 3 times.
240+
// 1st time -> before we call this function
241+
// 2nd time -> when we check if we have to do this loop again (because do {} while (check))
242+
// .. instead of
243+
// 1st time -> before we call this function
244+
// 2nd time -> when we check the first time (because while (check) do {})
245+
// 3rd time -> when we re-check to see if we should do this loop again
246+
} while (hasAtRule(css, 'apply'))
236247

237248
return css
238249
}

0 commit comments

Comments
 (0)