Skip to content

Commit 490f1bc

Browse files
schmidt-sebastianjeremyjiang-dev
authored andcommitted
Prefer arrayValue when sorting FieldIndex (#3435)
1 parent 84c2407 commit 490f1bc

File tree

2 files changed

+2
-16
lines changed

2 files changed

+2
-16
lines changed

firebase-firestore/src/main/java/com/google/firebase/firestore/index/IndexEntry.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,9 @@
1515
package com.google.firebase.firestore.index;
1616

1717
import static com.google.firebase.firestore.util.Util.compareByteArrays;
18-
import static com.google.firebase.firestore.util.Util.nullSafeCompare;
1918

2019
import com.google.auto.value.AutoValue;
2120
import com.google.firebase.firestore.model.DocumentKey;
22-
import com.google.firebase.firestore.util.Util;
2321

2422
/** Represents an index entry saved by the SDK in its local storage. */
2523
@AutoValue
@@ -48,9 +46,9 @@ public int compareTo(IndexEntry other) {
4846
cmp = getDocumentKey().compareTo(other.getDocumentKey());
4947
if (cmp != 0) return cmp;
5048

51-
cmp = compareByteArrays(getDirectionalValue(), other.getDirectionalValue());
49+
cmp = compareByteArrays(getArrayValue(), other.getArrayValue());
5250
if (cmp != 0) return cmp;
5351

54-
return nullSafeCompare(getArrayValue(), other.getArrayValue(), Util::compareByteArrays);
52+
return compareByteArrays(getDirectionalValue(), other.getDirectionalValue());
5553
}
5654
}

firebase-firestore/src/main/java/com/google/firebase/firestore/util/Util.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -214,18 +214,6 @@ public static void crashMainThread(RuntimeException exception) {
214214
});
215215
}
216216

217-
public static <T> int nullSafeCompare(
218-
@Nullable T left, @Nullable T right, Comparator<T> comparator) {
219-
if (left != null && right != null) {
220-
return comparator.compare(left, right);
221-
}
222-
return left == null ? (right == null ? 0 : -1) : 1;
223-
}
224-
225-
public static <T extends Comparable<T>> int nullSafeCompare(@Nullable T left, @Nullable T right) {
226-
return nullSafeCompare(left, right, Comparable::compareTo);
227-
}
228-
229217
public static int compareByteArrays(byte[] left, byte[] right) {
230218
int size = Math.min(left.length, right.length);
231219
for (int i = 0; i < size; i++) {

0 commit comments

Comments
 (0)