Skip to content

Commit 510513b

Browse files
committed
replace absl::flat_hash_map
1 parent 1cce11c commit 510513b

File tree

7 files changed

+30
-12
lines changed

7 files changed

+30
-12
lines changed

Firestore/core/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ target_compile_definitions(
137137
target_link_libraries(
138138
firestore_util PUBLIC
139139
absl::base
140-
absl::flat_hash_map
141140
absl::memory
142141
absl::meta
143142
absl::optional
@@ -250,7 +249,6 @@ target_link_libraries(
250249
firestore_core PUBLIC
251250
LevelDB::LevelDB
252251
absl::base
253-
absl::flat_hash_map
254252
absl::memory
255253
absl::meta
256254
absl::optional

Firestore/core/src/model/object_value.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,12 @@ ObjectValue ObjectValue::FromFieldsEntry(
227227
return ObjectValue{std::move(value)};
228228
}
229229

230+
// TODO(b/443765747) Revert back to absl::flat_hash_map after the absl version
231+
// is upgraded to later than 20250127.0
230232
ObjectValue ObjectValue::FromAggregateFieldsEntry(
231233
google_firestore_v1_AggregationResult_AggregateFieldsEntry* fields_entry,
232234
pb_size_t count,
233-
const absl::flat_hash_map<std::string, std::string>& aliasMap) {
235+
const std::unordered_map<std::string, std::string>& aliasMap) {
234236
Message<google_firestore_v1_Value> value;
235237
value->which_value_type = google_firestore_v1_Value_map_value_tag;
236238

@@ -246,7 +248,9 @@ ObjectValue ObjectValue::FromAggregateFieldsEntry(
246248
// using the client-side alias.
247249
ByteString serverAlias(entry.key);
248250
std::string serverAliasString = serverAlias.ToString();
249-
HARD_ASSERT(aliasMap.contains(serverAliasString),
251+
// TODO(b/443765747) Revert back to aliasMap.contains(serverAliasString)
252+
// after the absl version is upgraded to later than 20250127.0
253+
HARD_ASSERT(aliasMap.find(serverAliasString) != aliasMap.end(),
250254
"%s not present in aliasMap", serverAlias.ToString());
251255

252256
ByteString clientAlias(aliasMap.find(serverAliasString)->second);

Firestore/core/src/model/object_value.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,12 @@ class ObjectValue {
7878
* @param count Count of fields in `fields_entry`.
7979
* @return The created `ObjectValue`.
8080
*/
81+
// TODO(b/443765747) Revert back to absl::flat_hash_map after the absl version
82+
// is upgraded to later than 20250127.0
8183
static ObjectValue FromAggregateFieldsEntry(
8284
google_firestore_v1_AggregationResult_AggregateFieldsEntry* fields_entry,
8385
pb_size_t count,
84-
const absl::flat_hash_map<std::string, std::string>& aliasMap);
86+
const std::unordered_map<std::string, std::string>& aliasMap);
8587

8688
/** Recursively extracts the FieldPaths that are set in this ObjectValue. */
8789
FieldMask ToFieldMask() const;

Firestore/core/src/remote/datastore.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,9 @@ void Datastore::RunAggregateQueryWithCredentials(
281281
const core::Query& query,
282282
const std::vector<AggregateField>& aggregates,
283283
api::AggregateQueryCallback&& callback) {
284-
absl::flat_hash_map<std::string, std::string> aliasMap;
284+
// TODO(b/443765747) Revert back to absl::flat_hash_map after the absl version
285+
// is upgraded to later than 20250127.0
286+
std::unordered_map<std::string, std::string> aliasMap;
285287
grpc::ByteBuffer message =
286288
MakeByteBuffer(datastore_serializer_.EncodeAggregateQueryRequest(
287289
query, aggregates, aliasMap));

Firestore/core/src/remote/remote_objc_bridge.cc

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,11 +272,13 @@ DatastoreSerializer::MergeLookupResponses(
272272
return result;
273273
}
274274

275+
// TODO(b/443765747) Revert back to absl::flat_hash_map after the absl version
276+
// is upgraded to later than 20250127.0
275277
Message<google_firestore_v1_RunAggregationQueryRequest>
276278
DatastoreSerializer::EncodeAggregateQueryRequest(
277279
const core::Query& query,
278280
const std::vector<AggregateField>& aggregates,
279-
absl::flat_hash_map<std::string, std::string>& aliasMap) const {
281+
std::unordered_map<std::string, std::string>& aliasMap) const {
280282
Message<google_firestore_v1_RunAggregationQueryRequest> result;
281283
auto encodedTarget = serializer_.EncodeQueryTarget(query.ToAggregateTarget());
282284
result->parent = encodedTarget.parent;
@@ -291,7 +293,9 @@ DatastoreSerializer::EncodeAggregateQueryRequest(
291293
// De-duplicate aggregates based on the alias.
292294
// Since aliases are auto-computed from the operation and path,
293295
// equal aggregate will have the same alias.
294-
absl::flat_hash_map<std::string, AggregateField> uniqueAggregates;
296+
// TODO(b/443765747) Revert back to absl::flat_hash_map after the absl version
297+
// is upgraded to later than 20250127.0
298+
std::unordered_map<std::string, AggregateField> uniqueAggregates;
295299
for (const AggregateField& aggregate : aggregates) {
296300
auto pair = std::pair<std::string, AggregateField>(
297301
aggregate.alias.StringValue(), aggregate);
@@ -365,9 +369,11 @@ DatastoreSerializer::EncodeAggregateQueryRequest(
365369
return result;
366370
}
367371

372+
// TODO(b/443765747) Revert back to absl::flat_hash_map after the absl version
373+
// is upgraded to later than 20250127.0
368374
util::StatusOr<ObjectValue> DatastoreSerializer::DecodeAggregateQueryResponse(
369375
const grpc::ByteBuffer& response,
370-
const absl::flat_hash_map<std::string, std::string>& aliasMap) const {
376+
const std::unordered_map<std::string, std::string>& aliasMap) const {
371377
ByteBufferReader reader{response};
372378
auto message =
373379
Message<google_firestore_v1_RunAggregationQueryResponse>::TryParse(

Firestore/core/src/remote/remote_objc_bridge.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,19 @@ class DatastoreSerializer {
136136
util::StatusOr<std::vector<model::Document>> MergeLookupResponses(
137137
const std::vector<grpc::ByteBuffer>& responses) const;
138138

139+
// TODO(b/443765747) Revert back to absl::flat_hash_map after the absl version
140+
// is upgraded to later than 20250127.0
139141
nanopb::Message<google_firestore_v1_RunAggregationQueryRequest>
140142
EncodeAggregateQueryRequest(
141143
const core::Query& query,
142144
const std::vector<model::AggregateField>& aggregates,
143-
absl::flat_hash_map<std::string, std::string>& aliasMap) const;
145+
std::unordered_map<std::string, std::string>& aliasMap) const;
144146

147+
// TODO(b/443765747) Revert back to absl::flat_hash_map after the absl version
148+
// is upgraded to later than 20250127.0
145149
util::StatusOr<model::ObjectValue> DecodeAggregateQueryResponse(
146150
const grpc::ByteBuffer& response,
147-
const absl::flat_hash_map<std::string, std::string>& aliasMap) const;
151+
const std::unordered_map<std::string, std::string>& aliasMap) const;
148152

149153
const Serializer& serializer() const {
150154
return serializer_;

Firestore/core/test/unit/api/aggregate_query_test.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ TEST(AggregateQuery, GetCallsGetAggregateOk) {
110110
aggregate_fields_entry[0].value.integer_value = 10;
111111

112112
// Test alias map
113-
absl::flat_hash_map<std::string, std::string> alias_map;
113+
// TODO(b/443765747) Revert back to absl::flat_hash_map after the absl version
114+
// is upgraded to later than 20250127.0
115+
std::unordered_map<std::string, std::string> alias_map;
114116
alias_map["aggregate_0"] = "count";
115117

116118
// Test ObjectValue result

0 commit comments

Comments
 (0)