MCPcopy
hub / github.com/webpack/webpack / sortWith

Method sortWith

lib/util/SortableSet.js:88–102  ·  view source on GitHub ↗

* Sort with a comparer function * @param {SortFunction<T> | undefined} sortFn Sorting comparer function * @returns {void}

(sortFn)

Source from the content-addressed store, hash-verified

86 * @returns {void}
87 */
88 sortWith(sortFn) {
89 if (this.size <= 1 || sortFn === this._lastActiveSortFn) {
90 // already sorted - nothing to do
91 return;
92 }
93
94 /** @type {T[]} */
95 const sortedArray = [...this].sort(sortFn);
96 super.clear();
97 for (let i = 0; i < sortedArray.length; i += 1) {
98 super.add(sortedArray[i]);
99 }
100 this._lastActiveSortFn = sortFn;
101 this._invalidateCache();
102 }
103
104 sort() {
105 this.sortWith(this._sortFn);

Calls 4

_invalidateCacheMethod · 0.95
sortMethod · 0.80
clearMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected