Skip to content

Commit 65f16f1

Browse files
Use sorted map
1 parent a8db28d commit 65f16f1

File tree

4 files changed

+13
-16
lines changed

4 files changed

+13
-16
lines changed

FirebaseFirestore.podspec

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ Google Cloud Firestore is a NoSQL document database built for automatic scaling,
9090
s.dependency 'abseil/algorithm', abseil_version
9191
s.dependency 'abseil/base', abseil_version
9292
s.dependency 'abseil/container/flat_hash_map', abseil_version
93-
s.dependency 'abseil/container/flat_hash_set', abseil_version
9493
s.dependency 'abseil/memory', abseil_version
9594
s.dependency 'abseil/meta', abseil_version
9695
s.dependency 'abseil/strings/strings', abseil_version

Firestore/core/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ target_link_libraries(
133133
firestore_util PUBLIC
134134
absl::base
135135
absl::flat_hash_map
136-
absl::flat_hash_set
137136
absl::memory
138137
absl::meta
139138
absl::optional

Firestore/core/src/model/object_value.cc

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,13 @@
1717
#include "Firestore/core/src/model/object_value.h"
1818

1919
#include <algorithm>
20+
#include <map>
2021
#include <set>
2122

2223
#include "Firestore/Protos/nanopb/google/firestore/v1/document.nanopb.h"
2324
#include "Firestore/core/src/nanopb/fields_array.h"
2425
#include "Firestore/core/src/nanopb/message.h"
2526
#include "Firestore/core/src/nanopb/nanopb_util.h"
26-
#include "absl/container/flat_hash_map.h"
27-
#include "absl/container/flat_hash_set.h"
2827

2928
namespace firebase {
3029
namespace firestore {
@@ -75,16 +74,16 @@ google_firestore_v1_MapValue_FieldsEntry* FindEntry(
7574

7675
size_t CalculateSizeOfUnion(
7776
google_firestore_v1_MapValue* map_value,
78-
const absl::flat_hash_map<std::string, google_firestore_v1_Value>& upserts,
79-
const absl::flat_hash_set<std::string>& deletes) {
77+
const std::map<std::string, google_firestore_v1_Value>& upserts,
78+
const std::set<std::string>& deletes) {
8079
// Compute the size of the map after applying all mutations. The final size is
8180
// the number of existing entries, plus the number of new entries
8281
// minus the number of deleted entries.
8382
return upserts.size() +
8483
std::count_if(
8584
map_value->fields, map_value->fields + map_value->fields_count,
8685
[&](const google_firestore_v1_MapValue_FieldsEntry& entry) {
87-
absl::string_view field = MakeStringView(entry.key);
86+
std::string field = MakeString(entry.key);
8887
// Don't count if entry is deleted or if it is a replacement
8988
// rather than an insert.
9089
return deletes.find(field) == deletes.end() &&
@@ -98,8 +97,8 @@ size_t CalculateSizeOfUnion(
9897
*/
9998
void ApplyChanges(
10099
google_firestore_v1_MapValue* parent,
101-
const absl::flat_hash_map<std::string, google_firestore_v1_Value>& upserts,
102-
const absl::flat_hash_set<std::string>& deletes) {
100+
const std::map<std::string, google_firestore_v1_Value>& upserts,
101+
const std::set<std::string>& deletes) {
103102
// TODO(mrschmidt): Consider using `absl::btree_map` and `absl::btree_set` for
104103
// potentially better performance.
105104
auto source_count = parent->fields_count;
@@ -228,7 +227,7 @@ void MutableObjectValue::Set(const FieldPath& path,
228227
google_firestore_v1_MapValue* parent_map = ParentMap(path.PopLast());
229228

230229
std::string last_segment = path.last_segment();
231-
absl::flat_hash_map<std::string, google_firestore_v1_Value> upserts{
230+
std::map<std::string, google_firestore_v1_Value> upserts{
232231
{std::move(last_segment), value}};
233232

234233
ApplyChanges(parent_map, upserts, /*deletes=*/{});
@@ -238,8 +237,8 @@ void MutableObjectValue::SetAll(const FieldMask& field_mask,
238237
const MutableObjectValue& data) {
239238
FieldPath parent;
240239

241-
absl::flat_hash_map<std::string, google_firestore_v1_Value> upserts;
242-
absl::flat_hash_set<std::string> deletes;
240+
std::map<std::string, google_firestore_v1_Value> upserts;
241+
std::set<std::string> deletes;
243242

244243
for (const FieldPath& path : field_mask) {
245244
if (!parent.IsImmediateParentOf(path)) {
@@ -280,7 +279,7 @@ void MutableObjectValue::Delete(const FieldPath& path) {
280279
// We can only delete a leaf entry if its parent is a map.
281280
if (nested_value->which_value_type ==
282281
google_firestore_v1_Value_map_value_tag) {
283-
absl::flat_hash_set<std::string> deletes{path.last_segment()};
282+
std::set<std::string> deletes{path.last_segment()};
284283
ApplyChanges(&nested_value->map_value, /*upserts=*/{}, deletes);
285284
}
286285
}
@@ -314,7 +313,7 @@ google_firestore_v1_MapValue* MutableObjectValue::ParentMap(
314313
google_firestore_v1_Value new_entry{};
315314
new_entry.which_value_type = google_firestore_v1_Value_map_value_tag;
316315

317-
absl::flat_hash_map<std::string, google_firestore_v1_Value> upserts{
316+
std::map<std::string, google_firestore_v1_Value> upserts{
318317
{segment, new_entry}};
319318
ApplyChanges(&parent->map_value, upserts, /*deletes=*/{});
320319

Firestore/core/test/unit/model/value_util_test.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,13 @@ class ValueUtilTest : public ::testing::Test {
139139
[&] {
140140
nanopb::Message<google_firestore_v1_Value> clone2{DeepClone(value)};
141141
EXPECT_TRUE(value == *clone2)
142-
<< "Equality check failed for '" << value << "' (before cleanup)";
142+
<< "Equality failed for '" << CanonicalId(value) << "' (before free)";
143143
clone1 = nanopb::Message<google_firestore_v1_Value>{DeepClone(*clone2)};
144144
}();
145145

146146
// `clone2` is destroyed at this point, but `clone1` should be still valid.
147147
EXPECT_TRUE(value == *clone1)
148-
<< "Equality check failed for '" << value << "' (after cleanup)";
148+
<< "Equality failed for '" << CanonicalId(value) << "' (after free)";
149149
}
150150

151151
private:

0 commit comments

Comments
 (0)