Skip to content

Commit 0fa1b8e

Browse files
authored
Revert "Replace absl::optional usage in API (#8902)" (#8906)
This reverts commit 453a5cb.
1 parent 453a5cb commit 0fa1b8e

15 files changed

+36
-464
lines changed

Firestore/Source/API/FIRCollectionReference.mm

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
#include "Firestore/core/src/api/collection_reference.h"
2727
#include "Firestore/core/src/api/document_reference.h"
28-
#include "Firestore/core/src/api/optional.h"
2928
#include "Firestore/core/src/core/user_data.h"
3029
#include "Firestore/core/src/model/resource_path.h"
3130
#include "Firestore/core/src/util/error_apple.h"
@@ -34,7 +33,6 @@
3433

3534
using firebase::firestore::api::CollectionReference;
3635
using firebase::firestore::api::DocumentReference;
37-
using firebase::firestore::api::Optional;
3836
using firebase::firestore::core::ParsedSetData;
3937
using firebase::firestore::model::ResourcePath;
4038
using firebase::firestore::util::MakeCallback;
@@ -93,7 +91,7 @@ - (NSString *)collectionID {
9391
}
9492

9593
- (FIRDocumentReference *_Nullable)parent {
96-
Optional<DocumentReference> parent = self.reference.parent();
94+
absl::optional<DocumentReference> parent = self.reference.parent();
9795
if (!parent) {
9896
return nil;
9997
}

Firestore/Source/API/FIRDocumentSnapshot+Internal.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include <memory>
2020

2121
#include "Firestore/core/src/api/api_fwd.h"
22-
#include "Firestore/core/src/api/optional.h"
2322
#include "Firestore/core/src/model/model_fwd.h"
2423

2524
@class FIRFirestore;
@@ -49,7 +48,7 @@ NS_ASSUME_NONNULL_BEGIN
4948
/** Internal FIRDocumentSnapshot API we don't want exposed in our public header files. */
5049
@interface FIRDocumentSnapshot (Internal)
5150

52-
- (const api::Optional<model::Document> &)internalDocument;
51+
- (const absl::optional<model::Document> &)internalDocument;
5352

5453
@end
5554

Firestore/Source/API/FIRDocumentSnapshot.mm

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
#include "Firestore/core/src/api/document_reference.h"
3535
#include "Firestore/core/src/api/document_snapshot.h"
3636
#include "Firestore/core/src/api/firestore.h"
37-
#include "Firestore/core/src/api/optional.h"
3837
#include "Firestore/core/src/api/settings.h"
3938
#include "Firestore/core/src/model/database_id.h"
4039
#include "Firestore/core/src/model/document_key.h"
@@ -51,7 +50,6 @@
5150
using firebase::firestore::api::Firestore;
5251
using firebase::firestore::api::MakeFIRGeoPoint;
5352
using firebase::firestore::api::MakeFIRTimestamp;
54-
using firebase::firestore::api::Optional;
5553
using firebase::firestore::api::SnapshotMetadata;
5654
using firebase::firestore::model::DatabaseId;
5755
using firebase::firestore::model::Document;
@@ -128,7 +126,7 @@ - (BOOL)exists {
128126
return _snapshot.exists();
129127
}
130128

131-
- (const Optional<Document> &)internalDocument {
129+
- (const absl::optional<Document> &)internalDocument {
132130
return _snapshot.internal_document();
133131
}
134132

@@ -155,7 +153,7 @@ - (FIRSnapshotMetadata *)metadata {
155153

156154
- (nullable NSDictionary<NSString *, id> *)dataWithServerTimestampBehavior:
157155
(FIRServerTimestampBehavior)serverTimestampBehavior {
158-
Optional<google_firestore_v1_Value> data = _snapshot.GetValue(FieldPath::EmptyPath());
156+
absl::optional<google_firestore_v1_Value> data = _snapshot.GetValue(FieldPath::EmptyPath());
159157
if (!data) return nil;
160158

161159
FSTUserDataWriter *dataWriter =
@@ -178,7 +176,7 @@ - (nullable id)valueForField:(id)field
178176
} else {
179177
ThrowInvalidArgument("Subscript key must be an NSString or FIRFieldPath.");
180178
}
181-
Optional<google_firestore_v1_Value> fieldValue = _snapshot.GetValue(fieldPath);
179+
absl::optional<google_firestore_v1_Value> fieldValue = _snapshot.GetValue(fieldPath);
182180
if (!fieldValue) return nil;
183181
FSTUserDataWriter *dataWriter =
184182
[[FSTUserDataWriter alloc] initWithFirestore:_snapshot.firestore()

Firestore/core/src/api/collection_reference.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,12 @@ const std::string& CollectionReference::collection_id() const {
6767
return query().path().last_segment();
6868
}
6969

70-
Optional<DocumentReference> CollectionReference::parent() const {
70+
absl::optional<DocumentReference> CollectionReference::parent() const {
7171
ResourcePath parent_path = query().path().PopLast();
7272
if (parent_path.empty()) {
73-
return {};
73+
return absl::nullopt;
7474
} else {
75-
return Optional<DocumentReference>(
76-
DocumentReference(DocumentKey(std::move(parent_path)), firestore()));
75+
return DocumentReference(DocumentKey(std::move(parent_path)), firestore());
7776
}
7877
}
7978

Firestore/core/src/api/collection_reference.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
#include <string>
2222

2323
#include "Firestore/core/src/api/api_fwd.h"
24-
#include "Firestore/core/src/api/optional.h"
2524
#include "Firestore/core/src/api/query_core.h"
2625
#include "Firestore/core/src/core/core_fwd.h"
26+
#include "absl/types/optional.h"
2727

2828
namespace firebase {
2929
namespace firestore {
@@ -52,7 +52,7 @@ class CollectionReference : public Query {
5252
* For subcollections, `parent` returns the containing `DocumentReference`.
5353
* For root collections, nullopt is returned.
5454
*/
55-
Optional<DocumentReference> parent() const;
55+
absl::optional<DocumentReference> parent() const;
5656

5757
/**
5858
* A string containing the slash-separated path to this `CollectionReference`

Firestore/core/src/api/common.h

Lines changed: 0 additions & 130 deletions
This file was deleted.

Firestore/core/src/api/document_reference.cc

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include "Firestore/core/src/api/collection_reference.h"
2323
#include "Firestore/core/src/api/document_snapshot.h"
2424
#include "Firestore/core/src/api/firestore.h"
25-
#include "Firestore/core/src/api/optional.h"
2625
#include "Firestore/core/src/api/query_listener_registration.h"
2726
#include "Firestore/core/src/api/source.h"
2827
#include "Firestore/core/src/core/firestore_client.h"
@@ -220,9 +219,7 @@ std::unique_ptr<ListenerRegistration> DocumentReference::AddSnapshotListener(
220219
: false;
221220

222221
DocumentSnapshot result{
223-
firestore_, key_,
224-
document ? Optional<Document>(document.value())
225-
: Optional<Document>(),
222+
firestore_, key_, document,
226223
SnapshotMetadata{has_pending_writes, snapshot.from_cache()}};
227224
user_listener_->OnEvent(std::move(result));
228225
}

Firestore/core/src/api/document_snapshot.cc

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "Firestore/core/src/api/document_reference.h"
2222
#include "Firestore/core/src/model/resource_path.h"
2323
#include "Firestore/core/src/util/hashing.h"
24+
#include "absl/types/optional.h"
2425

2526
namespace firebase {
2627
namespace firestore {
@@ -35,22 +36,21 @@ DocumentSnapshot DocumentSnapshot::FromDocument(
3536
std::shared_ptr<Firestore> firestore,
3637
model::Document document,
3738
SnapshotMetadata metadata) {
38-
return DocumentSnapshot{std::move(firestore), document->key(),
39-
Optional<model::Document>(document),
39+
return DocumentSnapshot{std::move(firestore), document->key(), document,
4040
std::move(metadata)};
4141
}
4242

4343
DocumentSnapshot DocumentSnapshot::FromNoDocument(
4444
std::shared_ptr<Firestore> firestore,
4545
model::DocumentKey key,
4646
SnapshotMetadata metadata) {
47-
return DocumentSnapshot{std::move(firestore), std::move(key),
48-
Optional<model::Document>(), std::move(metadata)};
47+
return DocumentSnapshot{std::move(firestore), std::move(key), absl::nullopt,
48+
std::move(metadata)};
4949
}
5050

5151
DocumentSnapshot::DocumentSnapshot(std::shared_ptr<Firestore> firestore,
5252
model::DocumentKey document_key,
53-
Optional<Document> document,
53+
absl::optional<Document> document,
5454
SnapshotMetadata metadata)
5555
: firestore_{std::move(firestore)},
5656
internal_key_{std::move(document_key)},
@@ -67,7 +67,7 @@ bool DocumentSnapshot::exists() const {
6767
return internal_document_.has_value();
6868
}
6969

70-
const Optional<Document>& DocumentSnapshot::internal_document() const {
70+
const absl::optional<Document>& DocumentSnapshot::internal_document() const {
7171
return internal_document_;
7272
}
7373

@@ -79,15 +79,10 @@ const std::string& DocumentSnapshot::document_id() const {
7979
return internal_key_.path().last_segment();
8080
}
8181

82-
Optional<google_firestore_v1_Value> DocumentSnapshot::GetValue(
82+
absl::optional<google_firestore_v1_Value> DocumentSnapshot::GetValue(
8383
const FieldPath& field_path) const {
84-
if (internal_document_) {
85-
auto value = (*internal_document_)->field(field_path);
86-
if (value) {
87-
return Optional<google_firestore_v1_Value>(value.value());
88-
}
89-
}
90-
return {};
84+
return internal_document_ ? (*internal_document_)->field(field_path)
85+
: absl::nullopt;
9186
}
9287

9388
bool operator==(const DocumentSnapshot& lhs, const DocumentSnapshot& rhs) {

Firestore/core/src/api/document_snapshot.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@
2121
#include <string>
2222
#include <utility>
2323

24-
#include "Firestore/core/src/api/optional.h"
2524
#include "Firestore/core/src/api/snapshot_metadata.h"
2625
#include "Firestore/core/src/core/event_listener.h"
2726
#include "Firestore/core/src/model/document.h"
2827
#include "Firestore/core/src/model/document_key.h"
2928
#include "Firestore/core/src/model/model_fwd.h"
29+
#include "absl/types/optional.h"
3030

3131
namespace firebase {
3232
namespace firestore {
@@ -50,7 +50,7 @@ class DocumentSnapshot {
5050
size_t Hash() const;
5151

5252
bool exists() const;
53-
const Optional<model::Document>& internal_document() const;
53+
const absl::optional<model::Document>& internal_document() const;
5454
const std::string& document_id() const;
5555

5656
const SnapshotMetadata& metadata() const {
@@ -59,7 +59,7 @@ class DocumentSnapshot {
5959

6060
DocumentReference CreateReference() const;
6161

62-
Optional<google_firestore_v1_Value> GetValue(
62+
absl::optional<google_firestore_v1_Value> GetValue(
6363
const model::FieldPath& field_path) const;
6464

6565
const std::shared_ptr<Firestore>& firestore() const {
@@ -76,13 +76,13 @@ class DocumentSnapshot {
7676

7777
DocumentSnapshot(std::shared_ptr<Firestore> firestore,
7878
model::DocumentKey document_key,
79-
Optional<model::Document> document,
79+
absl::optional<model::Document> document,
8080
SnapshotMetadata metadata);
8181

8282
private:
8383
std::shared_ptr<Firestore> firestore_;
8484
model::DocumentKey internal_key_;
85-
Optional<model::Document> internal_document_;
85+
absl::optional<model::Document> internal_document_;
8686
SnapshotMetadata metadata_;
8787
};
8888

0 commit comments

Comments
 (0)