Skip to content

Commit

Permalink
Add optimization to SortedSet.unionWith (#2624)
Browse files Browse the repository at this point in the history
* Add optimization to SortedSet.unionWith

* Add changelog.

* Update changelog
  • Loading branch information
wu-hui authored Feb 13, 2020
1 parent 41132fa commit 2af214a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/firestore/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Unreleased
- [fixed] Fixed a performance regression introduced by the addition of
`Query.limitToLast(n: number)` in Firestore 1.7.0 (Firebase 7.3.0) (#2620).
- [fixed] Fixed an issue where `CollectionReference.add()` would reject
custom types when using `withConverter()`. (#2606)

Expand Down
7 changes: 7 additions & 0 deletions packages/firestore/src/util/sorted_set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,13 @@ export class SortedSet<T> {

unionWith(other: SortedSet<T>): SortedSet<T> {
let result: SortedSet<T> = this;

// Make sure `result` always refers to the larger one of the two sets.
if (result.size < other.size) {
result = other;
other = this;
}

other.forEach(elem => {
result = result.add(elem);
});
Expand Down
2 changes: 1 addition & 1 deletion packages/testing/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ function initializeApp(
({
getToken: async () => ({ accessToken: accessToken }),
getUid: () => null,
addAuthTokenListener: (listener) => {
addAuthTokenListener: listener => {
// Call listener once immediately with predefined accessToken.
listener(accessToken);
},
Expand Down

0 comments on commit 2af214a

Please sign in to comment.