Skip to content

Commit 7b60dc4

Browse files
authored
Firestore: minor tweaks to ThreadSafeMemozier code in response to code review feedback (#14633)
1 parent b1b5ce9 commit 7b60dc4

File tree

5 files changed

+8
-12
lines changed

5 files changed

+8
-12
lines changed

Firestore/core/src/core/filter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ class Filter {
164164
* Memoized list of all field filters that can be found by
165165
* traversing the tree of filters contained in this composite filter.
166166
*/
167-
mutable util::ThreadSafeMemoizer<std::vector<FieldFilter>>
167+
mutable util::ThreadSafeMemoizer<const std::vector<FieldFilter>>
168168
memoized_flattened_filters_;
169169
};
170170

Firestore/core/src/core/query.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ absl::optional<Operator> Query::FindOpInsideFilters(
9292
return absl::nullopt;
9393
}
9494

95-
std::shared_ptr<std::vector<OrderBy>> Query::CalculateNormalizedOrderBys()
95+
std::shared_ptr<const std::vector<OrderBy>> Query::CalculateNormalizedOrderBys()
9696
const {
9797
// Any explicit order by fields should be added as is.
9898
auto result = std::make_shared<std::vector<OrderBy>>(explicit_order_bys_);

Firestore/core/src/core/query.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -299,14 +299,10 @@ class Query {
299299

300300
Target ToTarget(const std::vector<OrderBy>& order_bys) const;
301301

302-
// For properties below, use a `std::shared_ptr<ThreadSafeMemoizer>` rather
303-
// than using `ThreadSafeMemoizer` directly so that this class is copyable
304-
// (`ThreadSafeMemoizer` is not copyable because of its `std::once_flag`
305-
// member variable, which is not copyable).
306-
307302
// The memoized list of sort orders.
308-
std::shared_ptr<std::vector<OrderBy>> CalculateNormalizedOrderBys() const;
309-
mutable util::ThreadSafeMemoizer<std::vector<OrderBy>>
303+
std::shared_ptr<const std::vector<OrderBy>> CalculateNormalizedOrderBys()
304+
const;
305+
mutable util::ThreadSafeMemoizer<const std::vector<OrderBy>>
310306
memoized_normalized_order_bys_;
311307

312308
// The corresponding Target of this Query instance.

Firestore/core/test/unit/util/thread_safe_memoizer_testing.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,15 @@ CountingFunc::CountingFunc(std::vector<std::string> chunks)
8181
std::function<std::shared_ptr<std::string>()> CountingFunc::func(
8282
std::string cookie) {
8383
return [this, cookie = std::move(cookie)] {
84-
return std::make_shared<std::string>(Next(cookie));
84+
return std::make_shared<std::string>(NextFuncReturnValue(cookie));
8585
};
8686
}
8787

8888
int CountingFunc::invocation_count() const {
8989
return count_.load(std::memory_order_acquire);
9090
}
9191

92-
std::string CountingFunc::Next(const std::string& cookie) {
92+
std::string CountingFunc::NextFuncReturnValue(const std::string& cookie) {
9393
const int id = count_.fetch_add(1, std::memory_order_acq_rel);
9494
std::ostringstream ss;
9595
for (const std::string& chunk : chunks_) {

Firestore/core/test/unit/util/thread_safe_memoizer_testing.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class CountingFunc {
9797
std::vector<std::string> chunks_;
9898

9999
explicit CountingFunc(std::vector<std::string> chunks);
100-
std::string Next(const std::string& cookie);
100+
std::string NextFuncReturnValue(const std::string& cookie);
101101
};
102102

103103
/**

0 commit comments

Comments
 (0)