diff --git a/classes/range.js b/classes/range.js index a791d912..988c6b7c 100644 --- a/classes/range.js +++ b/classes/range.js @@ -81,8 +81,8 @@ class Range { // memoize range parsing for performance. // this is a very hot path, and fully deterministic. - const memoOpts = Object.keys(this.options).join(',') - const memoKey = `parseRange:${memoOpts}:${range}` + const memoOpts = buildMemoKeyFromOptions(this.options) + const memoKey = memoOpts + ':' + range const cached = cache.get(memoKey) if (cached) { return cached @@ -190,6 +190,15 @@ class Range { return false } } + +function buildMemoKeyFromOptions (options) { + return ( + (options.loose ? 1 << 1 : 0) + | (options.includePrerelease ? 1 << 2 : 0) + | (options.rtl ? 1 << 3 : 0) + ) + '' +} + module.exports = Range const LRU = require('lru-cache')