Skip to content

Commit

Permalink
cleanup, simplify which variables we increment
Browse files Browse the repository at this point in the history
This also gets rid of some explanation that can now be omitted entirely.
  • Loading branch information
RobinMalfait committed Apr 15, 2024
1 parent d009534 commit 891dfa4
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions packages/tailwindcss/src/utils/compare.ts
Expand Up @@ -19,26 +19,16 @@ export function compare(a: string, z: string) {

// If both are numbers, compare them as numbers instead of strings.
if (aCode >= ZERO && aCode <= NINE && zCode >= ZERO && zCode <= NINE) {
let initialI = i
let aStart = i
let aEnd = i
let zStart = i
let zEnd = i

// Consume the number
while (a.charCodeAt(i) >= ZERO && a.charCodeAt(i) <= NINE) i++
let aEnd = i

// Reset `i` to its initial value, this way we can find the end of the
// number in `z`. If we don't do this, and use `i` as is it could be
// that we go past the number in `z` if `a` contains more digits.
//
// A side effect of re-setting `i` is that the `Number()` call will be
// much faster because if we didn't it could be that number for `z`
// looked like `50%` which is slower to parse than `50`.
i = initialI
while (a.charCodeAt(aEnd) >= ZERO && a.charCodeAt(aEnd) <= NINE) aEnd++

// Consume the number
while (z.charCodeAt(i) >= ZERO && z.charCodeAt(i) <= NINE) i++
let zEnd = i
while (z.charCodeAt(zEnd) >= ZERO && z.charCodeAt(zEnd) <= NINE) zEnd++

let aNumber = a.slice(aStart, aEnd)
let zNumber = z.slice(zStart, zEnd)
Expand Down

0 comments on commit 891dfa4

Please sign in to comment.