Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 61e6ea1

Browse filesBrowse files
authored
fix: faster cache key factory for range (#536)
1 parent f8b8b61 commit 61e6ea1
Copy full SHA for 61e6ea1

File tree

2 files changed

+8
-2
lines changed
Filter options

2 files changed

+8
-2
lines changed

‎classes/range.js

Copy file name to clipboardExpand all lines: classes/range.js
+6-2Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,10 @@ class Range {
8181

8282
// memoize range parsing for performance.
8383
// this is a very hot path, and fully deterministic.
84-
const memoOpts = Object.keys(this.options).join(',')
85-
const memoKey = `parseRange:${memoOpts}:${range}`
84+
const memoOpts =
85+
(this.options.includePrerelease && FLAG_INCLUDE_PRERELEASE) |
86+
(this.options.loose && FLAG_LOOSE)
87+
const memoKey = memoOpts + ':' + range
8688
const cached = cache.get(memoKey)
8789
if (cached) {
8890
return cached
@@ -190,6 +192,7 @@ class Range {
190192
return false
191193
}
192194
}
195+
193196
module.exports = Range
194197

195198
const LRU = require('lru-cache')
@@ -206,6 +209,7 @@ const {
206209
tildeTrimReplace,
207210
caretTrimReplace,
208211
} = require('../internal/re')
212+
const { FLAG_INCLUDE_PRERELEASE, FLAG_LOOSE } = require('../internal/constants')
209213

210214
const isNullSet = c => c.value === '<0.0.0-0'
211215
const isAny = c => c.value === ''

‎internal/constants.js

Copy file name to clipboardExpand all lines: internal/constants.js
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,6 @@ module.exports = {
2525
MAX_SAFE_INTEGER,
2626
RELEASE_TYPES,
2727
SEMVER_SPEC_VERSION,
28+
FLAG_INCLUDE_PRERELEASE: 0b001,
29+
FLAG_LOOSE: 0b010,
2830
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.