-
Notifications
You must be signed in to change notification settings - Fork 492
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This yields about a 10-20% speed improvement to a lot of common npm operations that spend most of their CPU time parsing a relatively small set of dependency ranges. It does mean that one `range.set` may contain the same Comparator objects as another range with the same sub-range. That was technically already possible, due to the `Comparator.ANY` magic range, but it did require a bit of tweaking in the `subset` function, which is also now a bit faster when calculating subsets for ranges that are partly or entirely identical.
- Loading branch information
Showing
8 changed files
with
118 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// parse out just the options we care about so we always get a consistent | ||
// obj with keys in a consistent order. | ||
const opts = ['includePrerelease', 'loose', 'rtl'] | ||
const parseOptions = options => | ||
!options ? {} | ||
: typeof options !== 'object' ? { loose: true } | ||
: opts.filter(k => options[k]).reduce((options, k) => { | ||
options[k] = true | ||
return options | ||
}, {}) | ||
module.exports = parseOptions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const t = require('tap') | ||
const parseOptions = require('../../internal/parse-options.js') | ||
|
||
t.test('falsey values always empty options object', t => { | ||
t.strictSame(parseOptions(null), {}) | ||
t.strictSame(parseOptions(false), {}) | ||
t.strictSame(parseOptions(undefined), {}) | ||
t.strictSame(parseOptions(), {}) | ||
t.strictSame(parseOptions(0), {}) | ||
t.strictSame(parseOptions(''), {}) | ||
t.end() | ||
}) | ||
|
||
t.test('truthy non-objects always loose mode, for backwards comp', t => { | ||
t.strictSame(parseOptions('hello'), {loose: true}) | ||
t.strictSame(parseOptions(true), {loose: true}) | ||
t.strictSame(parseOptions(1), {loose: true}) | ||
t.end() | ||
}) | ||
|
||
|
||
t.test('objects only include truthy flags we know about, set to true', t => { | ||
t.strictSame(parseOptions(/asdf/), {}) | ||
t.strictSame(parseOptions(new Error('hello')), {}) | ||
t.strictSame(parseOptions({loose: true,a:1,rtl:false}), { loose: true }) | ||
t.strictSame(parseOptions({loose: 1,rtl:2,includePrerelease:10}), { | ||
loose: true, | ||
rtl: true, | ||
includePrerelease: true, | ||
}) | ||
t.end() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters