2929import com .google .firebase .firestore .remote .TargetChange ;
3030import java .util .ArrayList ;
3131import java .util .Collections ;
32+ import java .util .Comparator ;
3233import java .util .List ;
3334import java .util .Map ;
3435
@@ -156,6 +157,7 @@ public DocumentChanges computeDocChanges(
156157 ? oldDocumentSet .getFirstDocument ()
157158 : null ;
158159
160+ Comparator <Document > queryComparator = query .comparator ();
159161 for (Map .Entry <DocumentKey , Document > entry : docChanges ) {
160162 DocumentKey key = entry .getKey ();
161163 Document oldDoc = oldDocumentSet .getDocument (key );
@@ -182,9 +184,9 @@ public DocumentChanges computeDocChanges(
182184 changeSet .addChange (DocumentViewChange .create (Type .MODIFIED , newDoc ));
183185 changeApplied = true ;
184186
185- if ((lastDocInLimit != null && query . comparator () .compare (newDoc , lastDocInLimit ) > 0 )
187+ if ((lastDocInLimit != null && queryComparator .compare (newDoc , lastDocInLimit ) > 0 )
186188 || (firstDocInLimit != null
187- && query . comparator () .compare (newDoc , firstDocInLimit ) < 0 )) {
189+ && queryComparator .compare (newDoc , firstDocInLimit ) < 0 )) {
188190 // This doc moved from inside the limit to outside the limit. That means there may be
189191 // some doc in the local cache that should be included instead.
190192 needsRefill = true ;
@@ -296,15 +298,17 @@ public ViewChange applyChanges(
296298 mutatedKeys = docChanges .mutatedKeys ;
297299
298300 // Sort changes based on type and query comparator.
301+
299302 List <DocumentViewChange > viewChanges = docChanges .changeSet .getChanges ();
303+ Comparator <Document > queryComparator = query .comparator ();
300304 Collections .sort (
301305 viewChanges ,
302306 (DocumentViewChange o1 , DocumentViewChange o2 ) -> {
303307 int typeComp = Integer .compare (View .changeTypeOrder (o1 ), View .changeTypeOrder (o2 ));
304308 if (typeComp != 0 ) {
305309 return typeComp ;
306310 }
307- return query . comparator () .compare (o1 .getDocument (), o2 .getDocument ());
311+ return queryComparator .compare (o1 .getDocument (), o2 .getDocument ());
308312 });
309313 applyTargetChange (targetChange );
310314 List <LimboDocumentChange > limboDocumentChanges =
0 commit comments