Skip to content

Commit 5f16dd8

Browse files
committed
clean up SortableSet
- remove unnecessary _isSorted flag - remove clear-override as an empty set is "sorted" - early return on empty sets
1 parent f7ffed8 commit 5f16dd8

1 file changed

Lines changed: 1 addition & 13 deletions

File tree

‎lib/util/SortableSet.js‎

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ module.exports = class SortableSet extends Set {
66
super(initialIterable);
77
this._sortFn = defaultSort;
88
this._lastActiveSortFn = null;
9-
this._isSorted = false;
109
}
1110

1211
/**
@@ -15,26 +14,16 @@ module.exports = class SortableSet extends Set {
1514
*/
1615
add(value) {
1716
this._lastActiveSortFn = null;
18-
this._isSorted = false;
1917
super.add(value);
2018
return this;
2119
}
2220

23-
/**
24-
* @returns {void}
25-
*/
26-
clear() {
27-
this._lastActiveSortFn = null;
28-
this._isSorted = false;
29-
super.clear();
30-
}
31-
3221
/**
3322
* @param {Function} sortFn - function to sort the set
3423
* @returns {void}
3524
*/
3625
sortWith(sortFn) {
37-
if(this._isSorted && sortFn === this._lastActiveSortFn) {
26+
if(this.size === 0 || sortFn === this._lastActiveSortFn) {
3827
// already sorted - nothing to do
3928
return;
4029
}
@@ -45,7 +34,6 @@ module.exports = class SortableSet extends Set {
4534
this.add(sortedArray[i]);
4635
}
4736
this._lastActiveSortFn = sortFn;
48-
this._isSorted = true;
4937
}
5038

5139
/**

0 commit comments

Comments
 (0)