diff --git a/classes/range.js b/classes/range.js index a791d912..29598bff 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,35 @@ class Range { return false } } + +function buildMemoKeyFromOptions (options) { + if (options.includePrerelease === true) { + if (options.loose === true && options.rtl === true) { + return '1' + } + + if (options.loose === true) { + return '2' + } + + if (options.rtl === true) { + return '3' + } + + return '4' + } else if (options.loose === true) { + if (options.rtl === true) { + return '5' + } + + return '6' + } else if (options.rtl === true) { + return '7' + } else { + return '8' + } +} + module.exports = Range const LRU = require('lru-cache')