Skip to content

Commit 637d76b

Browse files
committed
fix: fast path for compareIdentifiers when num
1 parent 11702f0 commit 637d76b

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

internal/identifiers.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
const numeric = /^[0-9]+$/
44
const compareIdentifiers = (a, b) => {
5+
if (typeof a === 'number' && typeof b === 'number') {
6+
return a === b ? 0 : a < b ? -1 : 1
7+
}
8+
59
const anum = numeric.test(a)
610
const bnum = numeric.test(b)
711

test/internal/identifiers.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ test('rcompareIdentifiers and compareIdentifiers', (t) => {
88
['1', '2'],
99
['alpha', 'beta'],
1010
['0', 'beta'],
11+
[1, 2],
1112
]
1213
set.forEach((ab) => {
1314
const a = ab[0]
@@ -17,5 +18,7 @@ test('rcompareIdentifiers and compareIdentifiers', (t) => {
1718
})
1819
t.equal(compareIdentifiers('0', '0'), 0)
1920
t.equal(rcompareIdentifiers('0', '0'), 0)
21+
t.equal(compareIdentifiers(1, 1), 0)
22+
t.equal(rcompareIdentifiers(1, 1), 0)
2023
t.end()
2124
})

0 commit comments

Comments
 (0)