aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firestore/Source/Local/FSTMemoryMutationQueue.mm
diff options
context:
space:
mode:
authorGravatar zxu <zxu@google.com>2018-03-23 17:52:01 -0400
committerGravatar GitHub <noreply@github.com>2018-03-23 17:52:01 -0400
commit0ccfd6a3dc77fb733626bc8911b5925ad9475c2e (patch)
treee3d443c4cd7410e09250999dbe0bda07df84d698 /Firestore/Source/Local/FSTMemoryMutationQueue.mm
parent6a61d83854fa7f0cc5898ee50c65169583a5b69c (diff)
port C++ `DocumentKey` to `Local/*` (#963)
* port C++ DocumentKey to Local's * address changes
Diffstat (limited to 'Firestore/Source/Local/FSTMemoryMutationQueue.mm')
-rw-r--r--Firestore/Source/Local/FSTMemoryMutationQueue.mm19
1 files changed, 10 insertions, 9 deletions
diff --git a/Firestore/Source/Local/FSTMemoryMutationQueue.mm b/Firestore/Source/Local/FSTMemoryMutationQueue.mm
index 8375efd..183a806 100644
--- a/Firestore/Source/Local/FSTMemoryMutationQueue.mm
+++ b/Firestore/Source/Local/FSTMemoryMutationQueue.mm
@@ -18,13 +18,14 @@
#import "Firestore/Source/Core/FSTQuery.h"
#import "Firestore/Source/Local/FSTDocumentReference.h"
-#import "Firestore/Source/Model/FSTDocumentKey.h"
#import "Firestore/Source/Model/FSTMutation.h"
#import "Firestore/Source/Model/FSTMutationBatch.h"
#import "Firestore/Source/Util/FSTAssert.h"
+#include "Firestore/core/src/firebase/firestore/model/document_key.h"
#include "Firestore/core/src/firebase/firestore/model/resource_path.h"
+using firebase::firestore::model::DocumentKey;
using firebase::firestore::model::ResourcePath;
NS_ASSUME_NONNULL_BEGIN
@@ -230,7 +231,7 @@ static const NSComparator NumberComparator = ^NSComparisonResult(NSNumber *left,
}
- (NSArray<FSTMutationBatch *> *)allMutationBatchesAffectingDocumentKey:
- (FSTDocumentKey *)documentKey {
+ (const DocumentKey &)documentKey {
FSTDocumentReference *start = [[FSTDocumentReference alloc] initWithKey:documentKey ID:0];
NSMutableArray<FSTMutationBatch *> *result = [NSMutableArray array];
@@ -258,17 +259,17 @@ static const NSComparator NumberComparator = ^NSComparisonResult(NSNumber *left,
// key in this reference must have an even number of segments. The empty segment can be used as
// a suffix of the query path because it precedes all other segments in an ordered traversal.
ResourcePath startPath = query.path;
- if (![FSTDocumentKey isDocumentKey:startPath]) {
+ if (!DocumentKey::IsDocumentKey(startPath)) {
startPath = startPath.Append("");
}
FSTDocumentReference *start =
- [[FSTDocumentReference alloc] initWithKey:[FSTDocumentKey keyWithPath:startPath] ID:0];
+ [[FSTDocumentReference alloc] initWithKey:DocumentKey{startPath} ID:0];
// Find unique batchIDs referenced by all documents potentially matching the query.
__block FSTImmutableSortedSet<NSNumber *> *uniqueBatchIDs =
[FSTImmutableSortedSet setWithComparator:NumberComparator];
FSTDocumentReferenceBlock block = ^(FSTDocumentReference *reference, BOOL *stop) {
- const ResourcePath &rowKeyPath = reference.key.path;
+ const ResourcePath &rowKeyPath = reference.key.path();
if (!prefix.IsPrefixOf(rowKeyPath)) {
*stop = YES;
return;
@@ -354,7 +355,7 @@ static const NSComparator NumberComparator = ^NSComparisonResult(NSNumber *left,
for (FSTMutationBatch *batch in batches) {
FSTBatchID batchID = batch.batchID;
for (FSTMutation *mutation in batch.mutations) {
- FSTDocumentKey *key = mutation.key;
+ const DocumentKey &key = mutation.key;
[garbageCollector addPotentialGarbageKey:key];
FSTDocumentReference *reference = [[FSTDocumentReference alloc] initWithKey:key ID:batchID];
@@ -373,15 +374,15 @@ static const NSComparator NumberComparator = ^NSComparisonResult(NSNumber *left,
#pragma mark - FSTGarbageSource implementation
-- (BOOL)containsKey:(FSTDocumentKey *)key {
+- (BOOL)containsKey:(const DocumentKey &)key {
// Create a reference with a zero ID as the start position to find any document reference with
// this key.
FSTDocumentReference *reference = [[FSTDocumentReference alloc] initWithKey:key ID:0];
NSEnumerator<FSTDocumentReference *> *enumerator =
[self.batchesByDocumentKey objectEnumeratorFrom:reference];
- FSTDocumentKey *_Nullable firstKey = [enumerator nextObject].key;
- return [firstKey isEqual:key];
+ FSTDocumentReference *_Nullable firstReference = [enumerator nextObject];
+ return firstReference && firstReference.key == reference.key;
}
#pragma mark - Helpers