-
Notifications
You must be signed in to change notification settings - Fork 216
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Choose better data structure for nodeWrappers.
Since NodeWrappers lists: * must be insertion ordered * must contain only unique values (based on their key) * support a fast existence / lookup operation This PR switches it from an array to a map. As broccoli pipelines grow large, simply searching the array to detect duplicates on insertion can become very costly, and switching to a Map addresses this specific bottleneck.
- Loading branch information
1 parent
69de985
commit f50639f
Showing
4 changed files
with
53 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
'use strict'; | ||
|
||
module.exports = function filterMap(iterator, cb) { | ||
const result = []; | ||
for (const entry of iterator) { | ||
if (cb(entry)) { | ||
result.push(entry); | ||
} | ||
} | ||
return result; | ||
}; |
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,15 @@ | ||
'use strict'; | ||
|
||
const chai = require('chai'); | ||
const expect = chai.expect; | ||
const filterMap = require('../../lib/utils/filter-map'); | ||
|
||
describe('filterMap', function() { | ||
it('works', function() { | ||
expect(filterMap([], () => true)).to.eql([]); | ||
expect(filterMap([1, false, 2], () => true)).to.eql([1, false, 2]); | ||
expect(filterMap([1, true, 2], () => false)).to.eql([]); | ||
expect(filterMap([1, true, 2], x => x === 1)).to.eql([1]); | ||
expect(filterMap([1, true, 2], x => typeof x === 'number')).to.eql([1, 2]); | ||
}); | ||
}); |