Skip to content

Commit 94af683

Browse files
committed
Update function so looks more like it did before
1 parent e9e55b0 commit 94af683

File tree

1 file changed

+18
-21
lines changed

1 file changed

+18
-21
lines changed

packages/tailwindcss/src/utils/compare.ts

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,24 @@ export function compare(a: string, z: string) {
1616

1717
// If both are numbers, compare them as numbers instead of strings.
1818
if (aCode >= ZERO && aCode <= NINE && zCode >= ZERO && zCode <= NINE) {
19-
let aValue = 0
20-
let zValue = 0
21-
let aEnd = i
22-
let zEnd = i
23-
24-
do {
25-
aValue *= 10
26-
aValue += a.charCodeAt(aEnd) - ZERO
27-
aCode = a.charCodeAt(++aEnd)
28-
} while (aCode >= ZERO && aCode <= NINE)
29-
30-
do {
31-
zValue *= 10
32-
zValue += z.charCodeAt(zEnd) - ZERO
33-
zCode = z.charCodeAt(++zEnd)
34-
} while (zCode >= ZERO && zCode <= NINE)
35-
36-
if (aValue - zValue) return aValue - zValue
37-
38-
let aNumber = a.slice(i, aEnd)
39-
let zNumber = z.slice(i, zEnd)
19+
let aStart = i
20+
let aEnd = i + 1
21+
let zStart = i
22+
let zEnd = i + 1
23+
24+
// Consume the number
25+
aCode = a.charCodeAt(aEnd)
26+
while (aCode >= ZERO && aCode <= NINE) aCode = a.charCodeAt(++aEnd)
27+
28+
// Consume the number
29+
zCode = z.charCodeAt(zEnd)
30+
while (zCode >= ZERO && zCode <= NINE) zCode = z.charCodeAt(++zEnd)
31+
32+
let aNumber = a.slice(aStart, aEnd)
33+
let zNumber = z.slice(zStart, zEnd)
34+
35+
let diff = Number(aNumber) - Number(zNumber)
36+
if (diff) return diff
4037

4138
// Fallback case if numbers are the same but the string representation
4239
// is not. Fallback to string sorting. E.g.: `0123` vs `123`

0 commit comments

Comments
 (0)