aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firestore/Source/Local/FSTLevelDBKey.mm
diff options
context:
space:
mode:
authorGravatar zxu <zxu@google.com>2018-03-06 14:28:04 -0500
committerGravatar GitHub <noreply@github.com>2018-03-06 14:28:04 -0500
commit8311c6432ecff78bedd13e27f64d241659324786 (patch)
tree982484ba69cf17172ee4e1308254a0b76894b7d5 /Firestore/Source/Local/FSTLevelDBKey.mm
parent34ebf10b0acc65f1924d723e82085d4104bc281d (diff)
port paths to FSTDocumentKey (#877)
* replace path with C++ implementation in FSTDocumentKey.{h,mm} only * address changes * address changes
Diffstat (limited to 'Firestore/Source/Local/FSTLevelDBKey.mm')
-rw-r--r--Firestore/Source/Local/FSTLevelDBKey.mm25
1 files changed, 15 insertions, 10 deletions
diff --git a/Firestore/Source/Local/FSTLevelDBKey.mm b/Firestore/Source/Local/FSTLevelDBKey.mm
index 41aea39..bd7b44a 100644
--- a/Firestore/Source/Local/FSTLevelDBKey.mm
+++ b/Firestore/Source/Local/FSTLevelDBKey.mm
@@ -17,12 +17,18 @@
#import "Firestore/Source/Local/FSTLevelDBKey.h"
#include <string>
+#include <utility>
+#include <vector>
#import "Firestore/Source/Model/FSTDocumentKey.h"
#import "Firestore/Source/Model/FSTPath.h"
+#include "Firestore/core/src/firebase/firestore/model/resource_path.h"
#include "Firestore/core/src/firebase/firestore/util/ordered_code.h"
+namespace util = firebase::firestore::util;
+using firebase::firestore::model::ResourcePath;
+
NS_ASSUME_NONNULL_BEGIN
using firebase::firestore::util::OrderedCode;
@@ -271,7 +277,7 @@ BOOL ReadDocumentKey(Slice *contents, FSTDocumentKey *__strong *result) {
Slice completeSegments = *contents;
std::string segment;
- NSMutableArray<NSString *> *pathSegments = [NSMutableArray array];
+ std::vector<std::string> path_segments{};
for (;;) {
// Advance a temporary slice to avoid advancing contents into the next key component which may
// not be a path segment.
@@ -283,15 +289,14 @@ BOOL ReadDocumentKey(Slice *contents, FSTDocumentKey *__strong *result) {
return NO;
}
- NSString *pathSegment = [[NSString alloc] initWithUTF8String:segment.c_str()];
- [pathSegments addObject:pathSegment];
+ path_segments.push_back(std::move(segment));
segment.clear();
completeSegments = leveldb::Slice(readPosition.data(), readPosition.size());
}
- FSTResourcePath *path = [FSTResourcePath pathWithSegments:pathSegments];
- if (path.length > 0 && [FSTDocumentKey isDocumentKey:path]) {
+ ResourcePath path{std::move(path_segments)};
+ if (path.size() > 0 && [FSTDocumentKey isDocumentKey:path]) {
*contents = completeSegments;
*result = [FSTDocumentKey keyWithPath:path];
return YES;
@@ -391,7 +396,7 @@ NSString *InvalidKey(const Slice &key) {
if (!ReadDocumentKey(&tmp, &documentKey)) {
break;
}
- [description appendFormat:@" key=%@", [documentKey.path description]];
+ [description appendFormat:@" key=%s", documentKey.path.CanonicalString().c_str()];
} else if (label == FSTComponentLabelTableName) {
std::string table;
@@ -531,7 +536,7 @@ NSString *InvalidKey(const Slice &key) {
std::string result;
WriteTableName(&result, kDocumentMutationsTable);
WriteUserID(&result, userID);
- WriteResourcePath(&result, documentKey.path);
+ WriteResourcePath(&result, [FSTResourcePath resourcePathWithCPPResourcePath:documentKey.path]);
WriteBatchID(&result, batchID);
WriteTerminator(&result);
return result;
@@ -685,7 +690,7 @@ NSString *InvalidKey(const Slice &key) {
std::string result;
WriteTableName(&result, kTargetDocumentsTable);
WriteTargetID(&result, targetID);
- WriteResourcePath(&result, documentKey.path);
+ WriteResourcePath(&result, [FSTResourcePath resourcePathWithCPPResourcePath:documentKey.path]);
WriteTerminator(&result);
return result;
}
@@ -719,7 +724,7 @@ NSString *InvalidKey(const Slice &key) {
+ (std::string)keyWithDocumentKey:(FSTDocumentKey *)documentKey targetID:(FSTTargetID)targetID {
std::string result;
WriteTableName(&result, kDocumentTargetsTable);
- WriteResourcePath(&result, documentKey.path);
+ WriteResourcePath(&result, [FSTResourcePath resourcePathWithCPPResourcePath:documentKey.path]);
WriteTargetID(&result, targetID);
WriteTerminator(&result);
return result;
@@ -754,7 +759,7 @@ NSString *InvalidKey(const Slice &key) {
+ (std::string)keyWithDocumentKey:(FSTDocumentKey *)key {
std::string result;
WriteTableName(&result, kRemoteDocumentsTable);
- WriteResourcePath(&result, key.path);
+ WriteResourcePath(&result, [FSTResourcePath resourcePathWithCPPResourcePath:key.path]);
WriteTerminator(&result);
return result;
}