Skip to content

Commit d85bf4e

Browse files
committed
Review feedback
1 parent ba38b49 commit d85bf4e

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

Firestore/Example/Tests/SpecTests/FSTSyncEngineTestDriver.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ - (void)receiveWatchStreamError:(int)errorCode userInfo:(NSDictionary<NSString *
413413
_workerQueue->EnqueueBlocking([&] {
414414
_datastore->FailWatchStream(error);
415415
// Unlike web, stream should re-open synchronously (if we have any listeners)
416-
if (_queryListeners.size() > 0) {
416+
if (!_queryListeners.empty()) {
417417
HARD_ASSERT(_datastore->IsWatchStreamOpen(), "Watch stream is open");
418418
}
419419
});

Firestore/Source/Core/FSTEventManager.mm

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656

5757
void Erase(const std::shared_ptr<QueryListener> &listener) {
5858
auto found = absl::c_find(listeners, listener);
59-
HARD_ASSERT(found != listeners.end(), "Shouldn't remove listeners that don't exist");
6059
if (found != listeners.end()) {
6160
listeners.erase(found);
6261
}
@@ -71,7 +70,8 @@ void set_view_snapshot(const absl::optional<ViewSnapshot> &snapshot) {
7170
}
7271

7372
private:
74-
// Enforce constness of this ViewSnapshot
73+
// Other members are public in this struct, ensure that any reads are
74+
// copies by requiring reads to go through a const getter.
7575
absl::optional<ViewSnapshot> snapshot_;
7676
};
7777

@@ -107,7 +107,7 @@ - (instancetype)initWithSyncEngine:(FSTSyncEngine *)syncEngine {
107107
- (TargetId)addListener:(std::shared_ptr<QueryListener>)listener {
108108
FSTQuery *query = listener->query();
109109

110-
auto inserted = _queries.insert({query, {}});
110+
auto inserted = _queries.emplace(query, QueryListenersInfo{});
111111
bool first_listen = inserted.second;
112112
QueryListenersInfo &query_info = inserted.first->second;
113113

@@ -127,13 +127,13 @@ - (TargetId)addListener:(std::shared_ptr<QueryListener>)listener {
127127

128128
- (void)removeListener:(const std::shared_ptr<QueryListener> &)listener {
129129
FSTQuery *query = listener->query();
130-
bool last_listen = NO;
130+
bool last_listen = false;
131131

132132
auto found_iter = _queries.find(query);
133133
if (found_iter != _queries.end()) {
134134
QueryListenersInfo &query_info = found_iter->second;
135135
query_info.Erase(listener);
136-
last_listen = (query_info.listeners.empty());
136+
last_listen = query_info.listeners.empty();
137137
}
138138

139139
if (last_listen) {

Firestore/core/src/firebase/firestore/core/query_listener.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017 Google
2+
* Copyright 2019 Google
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -88,7 +88,7 @@ class QueryListener {
8888
bool ShouldRaiseEvent(const ViewSnapshot& snapshot) const;
8989
void RaiseInitialEvent(const ViewSnapshot& snapshot);
9090

91-
FSTQuery* query_;
91+
FSTQuery* query_ = nil;
9292
ListenOptions options_;
9393

9494
/** The ViewSnapshotHandler associated with this query listener. */

Firestore/core/src/firebase/firestore/core/query_listener.mm

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017 Google
2+
* Copyright 2019 Google
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -93,7 +93,7 @@
9393
return true;
9494
}
9595

96-
// NOTE: We consider OnlineState.Unknown as online (it should become Offline
96+
// NOTE: We consider OnlineState::Unknown as online (it should become Offline
9797
// or Online if we wait long enough).
9898
bool maybe_online = online_state != OnlineState::Offline;
9999

@@ -110,7 +110,7 @@
110110
}
111111

112112
bool QueryListener::ShouldRaiseEvent(const ViewSnapshot& snapshot) const {
113-
// We don't need to handle includeDocumentMetadataChanges here because the
113+
// We don't need to handle include_document_metadata_changes() here because the
114114
// Metadata only changes have already been stripped out if needed. At this
115115
// point the only changes we will see are the ones we should propagate.
116116
if (!snapshot.document_changes().empty()) {
@@ -132,6 +132,7 @@
132132
void QueryListener::RaiseInitialEvent(const ViewSnapshot& snapshot) {
133133
HARD_ASSERT(!raised_initial_event_,
134134
"Trying to raise initial events for second time");
135+
135136
ViewSnapshot modified_snapshot = ViewSnapshot::FromInitialDocuments(
136137
snapshot.query(), snapshot.documents(), snapshot.mutated_keys(),
137138
snapshot.from_cache(), snapshot.excludes_metadata_changes());

0 commit comments

Comments
 (0)