aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firestore/Source/API
diff options
context:
space:
mode:
authorGravatar Gil <mcg@google.com>2018-02-22 08:12:54 -0800
committerGravatar GitHub <noreply@github.com>2018-02-22 08:12:54 -0800
commit935f3ca7d749f96c7207236a39c57f32a02c05d3 (patch)
tree94ac8094c8d10893f137325d5dc820e759dc6f90 /Firestore/Source/API
parent6ce954a791a73abc8d32765e2695ed153e120c47 (diff)
Avoid wrapping and rewrapping NSStrings when constructing DatabaseId (#833)
* Avoid wrapping and rewrapping NSStrings when constructing DatabaseId * Shorten DatabaseId::kDefaultDatabaseId
Diffstat (limited to 'Firestore/Source/API')
-rw-r--r--Firestore/Source/API/FIRFirestore+Internal.h5
-rw-r--r--Firestore/Source/API/FIRFirestore.mm18
2 files changed, 11 insertions, 12 deletions
diff --git a/Firestore/Source/API/FIRFirestore+Internal.h b/Firestore/Source/API/FIRFirestore+Internal.h
index 717a08b..7bc419a 100644
--- a/Firestore/Source/API/FIRFirestore+Internal.h
+++ b/Firestore/Source/API/FIRFirestore+Internal.h
@@ -17,6 +17,7 @@
#import "FIRFirestore.h"
#include "Firestore/core/src/firebase/firestore/model/database_id.h"
+#include "absl/strings/string_view.h"
NS_ASSUME_NONNULL_BEGIN
@@ -31,8 +32,8 @@ NS_ASSUME_NONNULL_BEGIN
* Initializes a Firestore object with all the required parameters directly. This exists so that
* tests can create FIRFirestore objects without needing FIRApp.
*/
-- (instancetype)initWithProjectID:(NSString *)projectID
- database:(NSString *)database
+- (instancetype)initWithProjectID:(const absl::string_view)projectID
+ database:(const absl::string_view)database
persistenceKey:(NSString *)persistenceKey
credentialsProvider:(id<FSTCredentialsProvider>)credentialsProvider
workerDispatchQueue:(FSTDispatchQueue *)workerDispatchQueue
diff --git a/Firestore/Source/API/FIRFirestore.mm b/Firestore/Source/API/FIRFirestore.mm
index 5a50710..ce8f8ab 100644
--- a/Firestore/Source/API/FIRFirestore.mm
+++ b/Firestore/Source/API/FIRFirestore.mm
@@ -117,13 +117,11 @@ extern "C" NSString *const FIRFirestoreErrorDomain = @"FIRFirestoreErrorDomain";
@"Failed to get FirebaseApp instance. Please call FirebaseApp.configure() "
@"before using Firestore");
}
- return
- [self firestoreForApp:app database:util::WrapNSStringNoCopy(DatabaseId::kDefaultDatabaseId)];
+ return [self firestoreForApp:app database:util::WrapNSStringNoCopy(DatabaseId::kDefault)];
}
+ (instancetype)firestoreForApp:(FIRApp *)app {
- return
- [self firestoreForApp:app database:util::WrapNSStringNoCopy(DatabaseId::kDefaultDatabaseId)];
+ return [self firestoreForApp:app database:util::WrapNSStringNoCopy(DatabaseId::kDefault)];
}
// TODO(b/62410906): make this public
@@ -137,7 +135,7 @@ extern "C" NSString *const FIRFirestoreErrorDomain = @"FIRFirestoreErrorDomain";
FSTThrowInvalidArgument(
@"database identifier may not be nil. Use '%@' if you want the default "
"database",
- util::WrapNSStringNoCopy(DatabaseId::kDefaultDatabaseId));
+ util::WrapNSStringNoCopy(DatabaseId::kDefault));
}
// Note: If the key format changes, please change the code that detects FIRApps being deleted
@@ -159,8 +157,8 @@ extern "C" NSString *const FIRFirestoreErrorDomain = @"FIRFirestoreErrorDomain";
NSString *persistenceKey = app.name;
- firestore = [[FIRFirestore alloc] initWithProjectID:projectID
- database:database
+ firestore = [[FIRFirestore alloc] initWithProjectID:util::MakeStringView(projectID)
+ database:util::MakeStringView(database)
persistenceKey:persistenceKey
credentialsProvider:credentialsProvider
workerDispatchQueue:workerDispatchQueue
@@ -172,14 +170,14 @@ extern "C" NSString *const FIRFirestoreErrorDomain = @"FIRFirestoreErrorDomain";
}
}
-- (instancetype)initWithProjectID:(NSString *)projectID
- database:(NSString *)database
+- (instancetype)initWithProjectID:(const absl::string_view)projectID
+ database:(const absl::string_view)database
persistenceKey:(NSString *)persistenceKey
credentialsProvider:(id<FSTCredentialsProvider>)credentialsProvider
workerDispatchQueue:(FSTDispatchQueue *)workerDispatchQueue
firebaseApp:(FIRApp *)app {
if (self = [super init]) {
- _databaseID = DatabaseId(util::MakeStringView(projectID), util::MakeStringView(database));
+ _databaseID = DatabaseId(projectID, database);
FSTPreConverterBlock block = ^id _Nullable(id _Nullable input) {
if ([input isKindOfClass:[FIRDocumentReference class]]) {
FIRDocumentReference *documentReference = (FIRDocumentReference *)input;