Skip to content

Commit

Permalink
perf: cache rbtree end iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
yaozilong.msy committed Aug 31, 2022
1 parent 4093492 commit 946f3d8
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions lib/rules/indent.js
Expand Up @@ -136,6 +136,7 @@ class BinarySearchTree {
*/
constructor() {
this._rbTree = new OrderedMap();
this._rbTreeEnd = this._rbTree.end();
}

/**
Expand Down Expand Up @@ -172,10 +173,19 @@ class BinarySearchTree {
return;
}
const iterator = this._rbTree.lowerBound(start);
const endIterator = this._rbTree.end();

while (!iterator.equals(endIterator) && iterator.pointer[0] < end) {
this._rbTree.eraseElementByIterator(iterator);
if (iterator.equals(this._rbTreeEnd)) {
return;
}

if (end > this._rbTree.back()[0]) {
while (!iterator.equals(this._rbTreeEnd)) {
this._rbTree.eraseElementByIterator(iterator);
}
} else {
while (iterator.pointer[0] < end) {
this._rbTree.eraseElementByIterator(iterator);
}
}
}
}
Expand Down

0 comments on commit 946f3d8

Please sign in to comment.