Skip to content

Commit 2edb91c

Browse files
authored
Add const for target index matcher (#11760)
1 parent 1dc90cd commit 2edb91c

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

Firestore/core/src/model/target_index_matcher.cc

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ TargetIndexMatcher::TargetIndexMatcher(const core::Target& target) {
5151
}
5252
}
5353

54-
bool TargetIndexMatcher::ServedByIndex(const model::FieldIndex& index) {
54+
bool TargetIndexMatcher::ServedByIndex(const model::FieldIndex& index) const {
5555
HARD_ASSERT(index.collection_group() == collection_id_,
5656
"Collection IDs do not match");
5757

@@ -118,7 +118,7 @@ bool TargetIndexMatcher::ServedByIndex(const model::FieldIndex& index) {
118118
return true;
119119
}
120120

121-
model::FieldIndex TargetIndexMatcher::BuildTargetIndex() {
121+
model::FieldIndex TargetIndexMatcher::BuildTargetIndex() const {
122122
// We want to make sure only one segment created for one field. For example,
123123
// in case like a == 3 and a > 2, Index: {a ASCENDING} will only be created
124124
// once.
@@ -175,7 +175,8 @@ model::FieldIndex TargetIndexMatcher::BuildTargetIndex() {
175175
std::move(segments), FieldIndex::InitialState());
176176
}
177177

178-
bool TargetIndexMatcher::HasMatchingEqualityFilter(const Segment& segment) {
178+
bool TargetIndexMatcher::HasMatchingEqualityFilter(
179+
const Segment& segment) const {
179180
for (const auto& filter : equality_filters_) {
180181
if (MatchesFilter(filter, segment)) {
181182
return true;
@@ -185,15 +186,16 @@ bool TargetIndexMatcher::HasMatchingEqualityFilter(const Segment& segment) {
185186
}
186187

187188
bool TargetIndexMatcher::MatchesFilter(
188-
const absl::optional<core::FieldFilter>& filter, const Segment& segment) {
189+
const absl::optional<core::FieldFilter>& filter,
190+
const Segment& segment) const {
189191
if (!filter.has_value()) {
190192
return false;
191193
}
192194
return MatchesFilter(filter.value(), segment);
193195
}
194196

195197
bool TargetIndexMatcher::MatchesFilter(const FieldFilter& filter,
196-
const Segment& segment) {
198+
const Segment& segment) const {
197199
if (filter.field() != segment.field_path()) {
198200
return false;
199201
}
@@ -204,7 +206,7 @@ bool TargetIndexMatcher::MatchesFilter(const FieldFilter& filter,
204206
}
205207

206208
bool TargetIndexMatcher::MatchesOrderBy(const OrderBy& order_by,
207-
const Segment& segment) {
209+
const Segment& segment) const {
208210
if (order_by.field() != segment.field_path()) {
209211
return false;
210212
}

Firestore/core/src/model/target_index_matcher.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,21 +75,21 @@ class TargetIndexMatcher {
7575
* clauses cannot be skipped, but a continuous OrderBy suffix may be
7676
* omitted.
7777
*/
78-
bool ServedByIndex(const model::FieldIndex& index);
78+
bool ServedByIndex(const model::FieldIndex& index) const;
7979

8080
/** Returns a full matched field index for this target. */
81-
model::FieldIndex BuildTargetIndex();
81+
model::FieldIndex BuildTargetIndex() const;
8282

8383
private:
84-
bool HasMatchingEqualityFilter(const model::Segment& segment);
84+
bool HasMatchingEqualityFilter(const model::Segment& segment) const;
8585

8686
bool MatchesFilter(const core::FieldFilter& filter,
87-
const model::Segment& segment);
87+
const model::Segment& segment) const;
8888
bool MatchesFilter(const absl::optional<core::FieldFilter>& filter,
89-
const model::Segment& segment);
89+
const model::Segment& segment) const;
9090

9191
bool MatchesOrderBy(const core::OrderBy& order_by,
92-
const model::Segment& segment);
92+
const model::Segment& segment) const;
9393

9494
// The collection ID (or collection group) of the query target.
9595
std::string collection_id_;

0 commit comments

Comments
 (0)