Skip to content

Commit

Permalink
🚀 perf(add): Only call subroutine if pair is not in the set yet.
Browse files Browse the repository at this point in the history
  • Loading branch information
make-github-pseudonymous-again committed Sep 1, 2020
1 parent 945d903 commit 9f3a69f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
9 changes: 6 additions & 3 deletions src/EfficientlyInvertiblePairs.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ export default class EfficientlyInvertiblePairs extends BasePairs {
}

add([A, B]) {
if (!this.has([A, B])) ++this.size;
insert(this._map, A, B);
insert(this._imap, B, A);
if (!this.has([A, B])) {
insert(this._map, A, B);
insert(this._imap, B, A);
++this.size;
}

return this;
}

Expand Down
7 changes: 5 additions & 2 deletions src/MemoryEfficientPairs.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ export default class MemoryEfficientPairs extends BasePairs {
}

add([A, B]) {
if (!this.has([A, B])) ++this.size;
insert(this._map, A, B);
if (!this.has([A, B])) {
insert(this._map, A, B);
++this.size;
}

return this;
}

Expand Down

0 comments on commit 9f3a69f

Please sign in to comment.