-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sortable set #5083
Sortable set #5083
Changes from 4 commits
0eaa847
747efca
4e5ef0d
bd8c6cf
1a16a3e
7a99930
f7ffed8
5f16dd8
b2a4244
8f3d65a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
"use strict"; | ||
|
||
module.exports = class SortableSet extends Set { | ||
|
||
constructor(initialIterable, defaultSort) { | ||
super(initialIterable); | ||
this._sortFn = defaultSort; | ||
} | ||
|
||
/** | ||
* @param {Function} sortFn - function to sort the set | ||
* @returns {void} | ||
*/ | ||
sortWith(sortFn) { | ||
const sortedArray = Array.from(this).sort(sortFn); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The original impl checked if the set was already sorted before sorting. The new SortableSet should do the same. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, I wasn't sure if this approach is ok and if I wanted to shadow as little as possible from the initial set (: happy to add some logic there |
||
this.clear(); | ||
for(let i = 0; i < sortedArray.length; i += 1) { | ||
this.add(sortedArray[i]); | ||
} | ||
} | ||
|
||
/** | ||
* @returns {void} | ||
*/ | ||
sort() { | ||
this.sortWith(this._sortFn); | ||
} | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ Child | |
[0] (webpack)/test/statsCases/scope-hoisting-multi/common_lazy_shared.js 25 bytes {0} {1} {2} [built] | ||
[1] (webpack)/test/statsCases/scope-hoisting-multi/vendor.js 25 bytes {5} [built] | ||
ModuleConcatenation (inner): module is an entrypoint | ||
[2] (webpack)/test/statsCases/scope-hoisting-multi/common.js + 1 modules 62 bytes {4} {3} [built] | ||
[2] (webpack)/test/statsCases/scope-hoisting-multi/common.js + 1 modules 62 bytes {3} {4} [built] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should not happen? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see: bd8c6cf
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah okey. 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seem to be different again... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ha yea, it tries to use the sort method from meh, i'd love to just have a |
||
[3] (webpack)/test/statsCases/scope-hoisting-multi/common_lazy.js 25 bytes {1} {2} [built] | ||
[4] (webpack)/test/statsCases/scope-hoisting-multi/first.js + 1 modules 238 bytes {4} [built] | ||
ModuleConcatenation (inner): module is an entrypoint | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why making this methods public? What was wrong with the original way, which hides them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initially I wanted to flip them, so
sortByXXX
was inModule
andChunk
would useModule.sortByXXX
to sort its Modules.As Module should know how to sort modules, not Chunk.
However node and circular dependencies let me down and so this is a left over of that approach, happy to make them private again, but I'd rather find a solution for the intial idea. :D