Skip to content

Commit d33af71

Browse files
committed
fix: faster cache key factory for range
1 parent da08e01 commit d33af71

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

classes/range.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ 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 = buildMemoKeyFromOptions(this.options)
85+
const memoKey = memoOpts + ':' + range
8686
const cached = cache.get(memoKey)
8787
if (cached) {
8888
return cached
@@ -190,6 +190,15 @@ class Range {
190190
return false
191191
}
192192
}
193+
194+
function buildMemoKeyFromOptions (options) {
195+
return (
196+
(options.loose ? 1 << 1 : 0)
197+
| (options.includePrerelease ? 1 << 2 : 0)
198+
| (options.rtl ? 1 << 3 : 0)
199+
) + ''
200+
}
201+
193202
module.exports = Range
194203

195204
const LRU = require('lru-cache')

0 commit comments

Comments
 (0)