Skip to content

Commit 2af214a

Browse files
authored
Add optimization to SortedSet.unionWith (#2624)
* Add optimization to SortedSet.unionWith * Add changelog. * Update changelog
1 parent 41132fa commit 2af214a

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

packages/firestore/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# Unreleased
2+
- [fixed] Fixed a performance regression introduced by the addition of
3+
`Query.limitToLast(n: number)` in Firestore 1.7.0 (Firebase 7.3.0) (#2620).
24
- [fixed] Fixed an issue where `CollectionReference.add()` would reject
35
custom types when using `withConverter()`. (#2606)
46

packages/firestore/src/util/sorted_set.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,13 @@ export class SortedSet<T> {
135135

136136
unionWith(other: SortedSet<T>): SortedSet<T> {
137137
let result: SortedSet<T> = this;
138+
139+
// Make sure `result` always refers to the larger one of the two sets.
140+
if (result.size < other.size) {
141+
result = other;
142+
other = this;
143+
}
144+
138145
other.forEach(elem => {
139146
result = result.add(elem);
140147
});

packages/testing/src/api/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ function initializeApp(
134134
({
135135
getToken: async () => ({ accessToken: accessToken }),
136136
getUid: () => null,
137-
addAuthTokenListener: (listener) => {
137+
addAuthTokenListener: listener => {
138138
// Call listener once immediately with predefined accessToken.
139139
listener(accessToken);
140140
},

0 commit comments

Comments
 (0)