Skip to content

Commit afbfb27

Browse files
authored
thread safe memoization (#11781)
1 parent 6adfba5 commit afbfb27

File tree

9 files changed

+220
-45
lines changed

9 files changed

+220
-45
lines changed

Firestore/Example/Firestore.xcodeproj/project.pbxproj

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
095A878BB33211AB52BFAD9F /* leveldb_document_overlay_cache_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = AE89CFF09C6804573841397F /* leveldb_document_overlay_cache_test.cc */; };
7474
0963F6D7B0F9AE1E24B82866 /* path_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = 403DBF6EFB541DFD01582AA3 /* path_test.cc */; };
7575
096BA3A3703AC1491F281618 /* index.pb.cc in Sources */ = {isa = PBXBuildFile; fileRef = 395E8B07639E69290A929695 /* index.pb.cc */; };
76+
09B83B26E47B6F6668DF54B8 /* thread_safe_memoizer_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = 1A8141230C7E3986EACEF0B6 /* thread_safe_memoizer_test.cc */; };
7677
09BE8C01EC33D1FD82262D5D /* aggregate_query_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = AF924C79F49F793992A84879 /* aggregate_query_test.cc */; };
7778
0A4E1B5E3E853763AE6ED7AE /* grpc_stream_tester.cc in Sources */ = {isa = PBXBuildFile; fileRef = 87553338E42B8ECA05BA987E /* grpc_stream_tester.cc */; };
7879
0A52B47C43B7602EE64F53A7 /* cc_compilation_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = 1B342370EAE3AA02393E33EB /* cc_compilation_test.cc */; };
@@ -229,6 +230,7 @@
229230
205601D1C6A40A4DD3BBAA04 /* target_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = 526D755F65AC676234F57125 /* target_test.cc */; };
230231
20814A477D00EA11D0E76631 /* FIRDocumentSnapshotTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5492E04B202154AA00B64F25 /* FIRDocumentSnapshotTests.mm */; };
231232
20A26E9D0336F7F32A098D05 /* Pods_Firestore_IntegrationTests_tvOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2220F583583EFC28DE792ABE /* Pods_Firestore_IntegrationTests_tvOS.framework */; };
233+
20A93AC59CD5A7AC41F10412 /* thread_safe_memoizer_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = 1A8141230C7E3986EACEF0B6 /* thread_safe_memoizer_test.cc */; };
232234
211A60ECA3976D27C0BF59BB /* md5_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = 3D050936A2D52257FD17FB6E /* md5_test.cc */; };
233235
21836C4D9D48F962E7A3A244 /* ordered_code_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = AB380D03201BC6E400D97691 /* ordered_code_test.cc */; };
234236
21A2A881F71CB825299DF06E /* hard_assert_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = 444B7AB3F5A2929070CB1363 /* hard_assert_test.cc */; };
@@ -500,6 +502,7 @@
500502
50454F81EC4584D4EB5F5ED5 /* serializer_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = 61F72C5520BC48FD001A68CB /* serializer_test.cc */; };
501503
50B749CA98365368AE34B71C /* filter_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = F02F734F272C3C70D1307076 /* filter_test.cc */; };
502504
50C852E08626CFA7DC889EEA /* field_index_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = BF76A8DA34B5B67B4DD74666 /* field_index_test.cc */; };
505+
51018EA27CF914DD1CC79CB3 /* thread_safe_memoizer_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = 1A8141230C7E3986EACEF0B6 /* thread_safe_memoizer_test.cc */; };
503506
513D34C9964E8C60C5C2EE1C /* leveldb_bundle_cache_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = 8E9CD82E60893DDD7757B798 /* leveldb_bundle_cache_test.cc */; };
504507
5150E9F256E6E82D6F3CB3F1 /* bundle_cache_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = F7FC06E0A47D393DE1759AE1 /* bundle_cache_test.cc */; };
505508
518BF03D57FBAD7C632D18F8 /* FIRQueryUnitTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = FF73B39D04D1760190E6B84A /* FIRQueryUnitTests.mm */; };
@@ -662,6 +665,7 @@
662665
5B4391097A6DF86EC3801DEE /* string_win_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = 79507DF8378D3C42F5B36268 /* string_win_test.cc */; };
663666
5B62003FEA9A3818FDF4E2DD /* document_key_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = B6152AD5202A5385000E5744 /* document_key_test.cc */; };
664667
5B89B1BA0AD400D9BF581420 /* listen_spec_test.json in Resources */ = {isa = PBXBuildFile; fileRef = 54DA12A01F315EE100DD57A1 /* listen_spec_test.json */; };
668+
5BB33F0BC7960D26062B07D3 /* thread_safe_memoizer_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = 1A8141230C7E3986EACEF0B6 /* thread_safe_memoizer_test.cc */; };
665669
5BC8406FD842B2FC2C200B2F /* stream_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = 5B5414D28802BC76FDADABD6 /* stream_test.cc */; };
666670
5BE49546D57C43DDFCDB6FBD /* to_string_apple_test.mm in Sources */ = {isa = PBXBuildFile; fileRef = B68B1E002213A764008977EF /* to_string_apple_test.mm */; };
667671
5C9B5696644675636A052018 /* token_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = A082AFDD981B07B5AD78FDE8 /* token_test.cc */; };
@@ -789,6 +793,7 @@
789793
6D7F70938662E8CA334F11C2 /* target_cache_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = B5C37696557C81A6C2B7271A /* target_cache_test.cc */; };
790794
6DBB3DB3FD6B4981B7F26A55 /* FIRQuerySnapshotTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5492E04F202154AA00B64F25 /* FIRQuerySnapshotTests.mm */; };
791795
6DCA8E54E652B78EFF3EEDAC /* XCTestCase+Await.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5492E0372021401E00B64F25 /* XCTestCase+Await.mm */; };
796+
6DFD49CCE2281CE243FEBB63 /* thread_safe_memoizer_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = 1A8141230C7E3986EACEF0B6 /* thread_safe_memoizer_test.cc */; };
792797
6E10507432E1D7AE658D16BD /* FSTSpecTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5492E03020213FFC00B64F25 /* FSTSpecTests.mm */; };
793798
6E4854B19B120C6F0F8192CC /* FSTAPIHelpers.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5492E04E202154AA00B64F25 /* FSTAPIHelpers.mm */; };
794799
6E59498D20F55BA800ECD9A5 /* FuzzingResources in Resources */ = {isa = PBXBuildFile; fileRef = 6ED6DEA120F5502700FC6076 /* FuzzingResources */; };
@@ -1162,6 +1167,7 @@
11621167
B2554A2BA211D10823646DBE /* Validation_BloomFilterTest_MD5_500_01_bloom_filter_proto.json in Resources */ = {isa = PBXBuildFile; fileRef = 4BD051DBE754950FEAC7A446 /* Validation_BloomFilterTest_MD5_500_01_bloom_filter_proto.json */; };
11631168
B28ACC69EB1F232AE612E77B /* async_testing.cc in Sources */ = {isa = PBXBuildFile; fileRef = 872C92ABD71B12784A1C5520 /* async_testing.cc */; };
11641169
B2A9965ED0114E39A911FD09 /* Validation_BloomFilterTest_MD5_5000_1_bloom_filter_proto.json in Resources */ = {isa = PBXBuildFile; fileRef = 4375BDCDBCA9938C7F086730 /* Validation_BloomFilterTest_MD5_5000_1_bloom_filter_proto.json */; };
1170+
B31B5E0D4EA72C5916CC71F5 /* thread_safe_memoizer_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = 1A8141230C7E3986EACEF0B6 /* thread_safe_memoizer_test.cc */; };
11651171
B371628DA91E80B64AE53085 /* FIRFieldPathTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5492E04C202154AA00B64F25 /* FIRFieldPathTests.mm */; };
11661172
B384E0F90D4CCC15C88CAF30 /* target_index_matcher_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = 63136A2371C0C013EC7A540C /* target_index_matcher_test.cc */; };
11671173
B3A309CCF5D75A555C7196E1 /* path_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = 403DBF6EFB541DFD01582AA3 /* path_test.cc */; };
@@ -1675,6 +1681,7 @@
16751681
132E32997D781B896672D30A /* reference_set_test.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = reference_set_test.cc; sourceTree = "<group>"; };
16761682
166CE73C03AB4366AAC5201C /* leveldb_index_manager_test.cc */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.cpp.cpp; path = leveldb_index_manager_test.cc; sourceTree = "<group>"; };
16771683
1A7D48A017ECB54FD381D126 /* Validation_BloomFilterTest_MD5_5000_1_membership_test_result.json */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.json; name = Validation_BloomFilterTest_MD5_5000_1_membership_test_result.json; path = bloom_filter_golden_test_data/Validation_BloomFilterTest_MD5_5000_1_membership_test_result.json; sourceTree = "<group>"; };
1684+
1A8141230C7E3986EACEF0B6 /* thread_safe_memoizer_test.cc */ = {isa = PBXFileReference; includeInIndex = 1; path = thread_safe_memoizer_test.cc; sourceTree = "<group>"; };
16781685
1B342370EAE3AA02393E33EB /* cc_compilation_test.cc */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.cpp.cpp; name = cc_compilation_test.cc; path = api/cc_compilation_test.cc; sourceTree = "<group>"; };
16791686
1B9F95EC29FAD3F100EEC075 /* FIRAggregateQueryUnitTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FIRAggregateQueryUnitTests.mm; sourceTree = "<group>"; };
16801687
1C01D8CE367C56BB2624E299 /* index.pb.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = index.pb.h; path = admin/index.pb.h; sourceTree = "<group>"; };
@@ -2361,6 +2368,7 @@
23612368
79507DF8378D3C42F5B36268 /* string_win_test.cc */,
23622369
899FC22684B0F7BEEAE13527 /* task_test.cc */,
23632370
A002425BC4FC4E805F4175B6 /* testing_hooks_test.cc */,
2371+
1A8141230C7E3986EACEF0B6 /* thread_safe_memoizer_test.cc */,
23642372
B68B1E002213A764008977EF /* to_string_apple_test.mm */,
23652373
B696858D2214B53900271095 /* to_string_test.cc */,
23662374
);
@@ -4260,6 +4268,7 @@
42604268
88929ED628DA8DD9592974ED /* task_test.cc in Sources */,
42614269
9B2C6A48A4DBD36080932B4E /* testing_hooks_test.cc in Sources */,
42624270
32A95242C56A1A230231DB6A /* testutil.cc in Sources */,
4271+
51018EA27CF914DD1CC79CB3 /* thread_safe_memoizer_test.cc in Sources */,
42634272
5497CB78229DECDE000FB92F /* time_testing.cc in Sources */,
42644273
ACC9369843F5ED3BD2284078 /* timestamp_test.cc in Sources */,
42654274
2AAEABFD550255271E3BAC91 /* to_string_apple_test.mm in Sources */,
@@ -4477,6 +4486,7 @@
44774486
67CF9FAA890307780731E1DA /* task_test.cc in Sources */,
44784487
24B75C63BDCD5551B2F69901 /* testing_hooks_test.cc in Sources */,
44794488
8388418F43042605FB9BFB92 /* testutil.cc in Sources */,
4489+
5BB33F0BC7960D26062B07D3 /* thread_safe_memoizer_test.cc in Sources */,
44804490
5497CB79229DECDE000FB92F /* time_testing.cc in Sources */,
44814491
26CB3D7C871BC56456C6021E /* timestamp_test.cc in Sources */,
44824492
5BE49546D57C43DDFCDB6FBD /* to_string_apple_test.mm in Sources */,
@@ -4715,6 +4725,7 @@
47154725
76A5447D76F060E996555109 /* task_test.cc in Sources */,
47164726
D0DA42DC66C4FE508A63B269 /* testing_hooks_test.cc in Sources */,
47174727
409C0F2BFC2E1BECFFAC4D32 /* testutil.cc in Sources */,
4728+
B31B5E0D4EA72C5916CC71F5 /* thread_safe_memoizer_test.cc in Sources */,
47184729
6300709ECDE8E0B5A8645F8D /* time_testing.cc in Sources */,
47194730
0CEE93636BA4852D3C5EC428 /* timestamp_test.cc in Sources */,
47204731
95DCD082374F871A86EF905F /* to_string_apple_test.mm in Sources */,
@@ -4953,6 +4964,7 @@
49534964
93C8F772F4DC5A985FA3D815 /* task_test.cc in Sources */,
49544965
F6738D3B72352BBEFB87172C /* testing_hooks_test.cc in Sources */,
49554966
A17DBC8F24127DA8A381F865 /* testutil.cc in Sources */,
4967+
09B83B26E47B6F6668DF54B8 /* thread_safe_memoizer_test.cc in Sources */,
49564968
A25FF76DEF542E01A2DF3B0E /* time_testing.cc in Sources */,
49574969
1E42CD0F60EB22A5D0C86D1F /* timestamp_test.cc in Sources */,
49584970
F9705E595FC3818F13F6375A /* to_string_apple_test.mm in Sources */,
@@ -5180,6 +5192,7 @@
51805192
662793139A36E5CFC935B949 /* task_test.cc in Sources */,
51815193
F184E5367DF3CA158EDE8532 /* testing_hooks_test.cc in Sources */,
51825194
54A0352A20A3B3BD003E0143 /* testutil.cc in Sources */,
5195+
20A93AC59CD5A7AC41F10412 /* thread_safe_memoizer_test.cc in Sources */,
51835196
5497CB77229DECDE000FB92F /* time_testing.cc in Sources */,
51845197
ABF6506C201131F8005F2C74 /* timestamp_test.cc in Sources */,
51855198
B68B1E012213A765008977EF /* to_string_apple_test.mm in Sources */,
@@ -5437,6 +5450,7 @@
54375450
C57B15CADD8C3E806B154C19 /* task_test.cc in Sources */,
54385451
5360D52DCAD1069B1E4B0B9D /* testing_hooks_test.cc in Sources */,
54395452
CA989C0E6020C372A62B7062 /* testutil.cc in Sources */,
5453+
6DFD49CCE2281CE243FEBB63 /* thread_safe_memoizer_test.cc in Sources */,
54405454
2D220B9ABFA36CD7AC43D0A7 /* time_testing.cc in Sources */,
54415455
D91D86B29B86A60C05879A48 /* timestamp_test.cc in Sources */,
54425456
60260A06871DCB1A5F3448D3 /* to_string_apple_test.mm in Sources */,

Firestore/core/src/core/composite_filter.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,14 @@ const model::FieldPath* CompositeFilter::Rep::GetFirstInequalityField() const {
154154

155155
const std::vector<FieldFilter>& CompositeFilter::Rep::GetFlattenedFilters()
156156
const {
157-
if (Filter::Rep::memoized_flattened_filters_.empty() && !filters().empty()) {
158-
for (const auto& filter : filters()) {
157+
return memoized_flattened_filters_->memoize([&]() {
158+
std::vector<FieldFilter> flattened_filters;
159+
for (const auto& filter : filters())
159160
std::copy(filter.GetFlattenedFilters().begin(),
160161
filter.GetFlattenedFilters().end(),
161-
std::back_inserter(Filter::Rep::memoized_flattened_filters_));
162-
}
163-
}
164-
return Filter::Rep::memoized_flattened_filters_;
162+
std::back_inserter(flattened_filters));
163+
return flattened_filters;
164+
});
165165
}
166166

167167
} // namespace core

Firestore/core/src/core/field_filter.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,10 @@ FieldFilter::FieldFilter(std::shared_ptr<const Filter::Rep> rep)
124124

125125
const std::vector<FieldFilter>& FieldFilter::Rep::GetFlattenedFilters() const {
126126
// This is already a field filter, so we return a vector of size one.
127-
if (Filter::Rep::memoized_flattened_filters_.empty()) {
128-
Filter::Rep::memoized_flattened_filters_ = std::vector<FieldFilter>{
127+
return memoized_flattened_filters_->memoize([&]() {
128+
return std::vector<FieldFilter>{
129129
FieldFilter(std::make_shared<const Rep>(*this))};
130-
}
131-
return Filter::Rep::memoized_flattened_filters_;
130+
});
132131
}
133132

134133
std::vector<Filter> FieldFilter::Rep::GetFilters() const {

Firestore/core/src/core/filter.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818

1919
#include <ostream>
2020

21+
#include "Firestore/core/src/core/field_filter.h"
22+
#include "Firestore/core/src/util/thread_safe_memoizer.h"
23+
2124
namespace firebase {
2225
namespace firestore {
2326
namespace core {
@@ -32,6 +35,12 @@ std::ostream& operator<<(std::ostream& os, const Filter& filter) {
3235
return os << filter.ToString();
3336
}
3437

38+
Filter::Rep::Rep()
39+
: memoized_flattened_filters_(
40+
std::make_shared<
41+
util::ThreadSafeMemoizer<std::vector<FieldFilter>>>()) {
42+
}
43+
3544
} // namespace core
3645
} // namespace firestore
3746
} // namespace firebase

Firestore/core/src/core/filter.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
#include <vector>
2424

2525
#include "Firestore/core/src/model/model_fwd.h"
26+
#include "Firestore/core/src/util/thread_safe_memoizer.h"
2627

2728
namespace firebase {
2829
namespace firestore {
29-
3030
namespace core {
3131

3232
class FieldFilter;
@@ -122,6 +122,8 @@ class Filter {
122122
protected:
123123
class Rep {
124124
public:
125+
Rep();
126+
125127
virtual ~Rep() = default;
126128

127129
virtual Type type() const {
@@ -162,8 +164,14 @@ class Filter {
162164
/**
163165
* Memoized list of all field filters that can be found by
164166
* traversing the tree of filters contained in this composite filter.
167+
*
168+
* Use a `std::shared_ptr<ThreadSafeMemoizer>` rather than using
169+
* `ThreadSafeMemoizer` directly so that this class is copyable
170+
* (`ThreadSafeMemoizer` is not copyable because of its `std::once_flag`
171+
* member variable, which is not copyable).
165172
*/
166-
mutable std::vector<FieldFilter> memoized_flattened_filters_;
173+
mutable std::shared_ptr<util::ThreadSafeMemoizer<std::vector<FieldFilter>>>
174+
memoized_flattened_filters_;
167175
};
168176

169177
explicit Filter(std::shared_ptr<const Rep>&& rep) : rep_(rep) {

Firestore/core/src/core/query.cc

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -90,19 +90,21 @@ absl::optional<Operator> Query::FindOpInsideFilters(
9090
}
9191

9292
const std::vector<OrderBy>& Query::normalized_order_bys() const {
93-
if (memoized_normalized_order_bys_.empty()) {
93+
return memoized_normalized_order_bys_->memoize([&]() {
94+
std::vector<OrderBy> result;
9495
const FieldPath* inequality_field = InequalityFilterField();
9596
const FieldPath* first_order_by_field = FirstOrderByField();
97+
9698
if (inequality_field && !first_order_by_field) {
9799
// In order to implicitly add key ordering, we must also add the
98100
// inequality filter field for it to be a valid query. Note that the
99101
// default inequality field and key ordering is ascending.
100102
if (inequality_field->IsKeyFieldPath()) {
101-
memoized_normalized_order_bys_ = {
103+
result = {
102104
OrderBy(FieldPath::KeyFieldPath(), Direction::Ascending),
103105
};
104106
} else {
105-
memoized_normalized_order_bys_ = {
107+
result = {
106108
OrderBy(*inequality_field, Direction::Ascending),
107109
OrderBy(FieldPath::KeyFieldPath(), Direction::Ascending),
108110
};
@@ -114,8 +116,7 @@ const std::vector<OrderBy>& Query::normalized_order_bys() const {
114116
first_order_by_field->CanonicalString(),
115117
inequality_field->CanonicalString());
116118

117-
std::vector<OrderBy> result = explicit_order_bys_;
118-
119+
result = explicit_order_bys_;
119120
bool found_explicit_key_order = false;
120121
for (const OrderBy& order_by : explicit_order_bys_) {
121122
if (order_by.field().IsKeyFieldPath()) {
@@ -132,11 +133,10 @@ const std::vector<OrderBy>& Query::normalized_order_bys() const {
132133
: explicit_order_bys_.back().direction();
133134
result.emplace_back(FieldPath::KeyFieldPath(), last_direction);
134135
}
135-
136-
memoized_normalized_order_bys_ = std::move(result);
137136
}
138-
}
139-
return memoized_normalized_order_bys_;
137+
138+
return result;
139+
});
140140
}
141141

142142
const FieldPath* Query::FirstOrderByField() const {
@@ -329,23 +329,16 @@ std::string Query::ToString() const {
329329
}
330330

331331
const Target& Query::ToTarget() const& {
332-
if (memoized_target == nullptr) {
333-
memoized_target = ToTarget(normalized_order_bys());
334-
}
335-
336-
return *memoized_target;
332+
return memoized_target_->memoize(
333+
[&]() { return ToTarget(normalized_order_bys()); });
337334
}
338335

339336
const Target& Query::ToAggregateTarget() const& {
340-
if (memoized_aggregate_target == nullptr) {
341-
memoized_aggregate_target = ToTarget(explicit_order_bys_);
342-
}
343-
344-
return *memoized_aggregate_target;
337+
return memoized_aggregate_target_->memoize(
338+
[&]() { return ToTarget(explicit_order_bys_); });
345339
}
346340

347-
const std::shared_ptr<const Target> Query::ToTarget(
348-
const std::vector<OrderBy>& order_bys) const& {
341+
Target Query::ToTarget(const std::vector<OrderBy>& order_bys) const {
349342
if (limit_type_ == LimitType::Last) {
350343
// Flip the orderBy directions since we want the last results
351344
std::vector<OrderBy> new_order_bys;
@@ -366,13 +359,11 @@ const std::shared_ptr<const Target> Query::ToTarget(
366359
start_at_->position(), start_at_->inclusive())}
367360
: absl::nullopt;
368361

369-
Target target(path(), collection_group(), filters(), new_order_bys, limit_,
362+
return Target(path(), collection_group(), filters(), new_order_bys, limit_,
370363
new_start_at, new_end_at);
371-
return std::make_shared<Target>(std::move(target));
372364
} else {
373-
Target target(path(), collection_group(), filters(), order_bys, limit_,
365+
return Target(path(), collection_group(), filters(), order_bys, limit_,
374366
start_at(), end_at());
375-
return std::make_shared<Target>(std::move(target));
376367
}
377368
}
378369

0 commit comments

Comments
 (0)