Skip to content

Commit 03315c7

Browse files
committed
fixup!: fast path for compareIdentifiers when num
1 parent 024ffda commit 03315c7

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

classes/semver.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,30 @@ class SemVer {
107107
}
108108

109109
compareMain (other) {
110+
// XXX compare already did this
110111
if (!(other instanceof SemVer)) {
111112
other = new SemVer(other, this.options)
112113
}
113114

114-
return (
115-
compareIdentifiers(this.major, other.major) ||
116-
compareIdentifiers(this.minor, other.minor) ||
117-
compareIdentifiers(this.patch, other.patch)
118-
)
115+
if (this.major < other.major) {
116+
return -1
117+
}
118+
if (this.major > other.major) {
119+
return 1
120+
}
121+
if (this.minor < other.minor) {
122+
return -1
123+
}
124+
if (this.minor > other.minor) {
125+
return 1
126+
}
127+
if (this.patch < other.patch) {
128+
return -1
129+
}
130+
if (this.patch > other.patch) {
131+
return 1
132+
}
133+
return 0
119134
}
120135

121136
comparePre (other) {

internal/identifiers.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
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-
95
const anum = numeric.test(a)
106
const bnum = numeric.test(b)
117

0 commit comments

Comments
 (0)