Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add const for target index matcher #11760

Merged
merged 1 commit into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions Firestore/core/src/model/target_index_matcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ TargetIndexMatcher::TargetIndexMatcher(const core::Target& target) {
}
}

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

Expand Down Expand Up @@ -118,7 +118,7 @@ bool TargetIndexMatcher::ServedByIndex(const model::FieldIndex& index) {
return true;
}

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

bool TargetIndexMatcher::HasMatchingEqualityFilter(const Segment& segment) {
bool TargetIndexMatcher::HasMatchingEqualityFilter(
const Segment& segment) const {
for (const auto& filter : equality_filters_) {
if (MatchesFilter(filter, segment)) {
return true;
Expand All @@ -185,15 +186,16 @@ bool TargetIndexMatcher::HasMatchingEqualityFilter(const Segment& segment) {
}

bool TargetIndexMatcher::MatchesFilter(
const absl::optional<core::FieldFilter>& filter, const Segment& segment) {
const absl::optional<core::FieldFilter>& filter,
const Segment& segment) const {
if (!filter.has_value()) {
return false;
}
return MatchesFilter(filter.value(), segment);
}

bool TargetIndexMatcher::MatchesFilter(const FieldFilter& filter,
const Segment& segment) {
const Segment& segment) const {
if (filter.field() != segment.field_path()) {
return false;
}
Expand All @@ -204,7 +206,7 @@ bool TargetIndexMatcher::MatchesFilter(const FieldFilter& filter,
}

bool TargetIndexMatcher::MatchesOrderBy(const OrderBy& order_by,
const Segment& segment) {
const Segment& segment) const {
if (order_by.field() != segment.field_path()) {
return false;
}
Expand Down
12 changes: 6 additions & 6 deletions Firestore/core/src/model/target_index_matcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,21 @@ class TargetIndexMatcher {
* clauses cannot be skipped, but a continuous OrderBy suffix may be
* omitted.
*/
bool ServedByIndex(const model::FieldIndex& index);
bool ServedByIndex(const model::FieldIndex& index) const;

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

private:
bool HasMatchingEqualityFilter(const model::Segment& segment);
bool HasMatchingEqualityFilter(const model::Segment& segment) const;

bool MatchesFilter(const core::FieldFilter& filter,
const model::Segment& segment);
const model::Segment& segment) const;
bool MatchesFilter(const absl::optional<core::FieldFilter>& filter,
const model::Segment& segment);
const model::Segment& segment) const;

bool MatchesOrderBy(const core::OrderBy& order_by,
const model::Segment& segment);
const model::Segment& segment) const;

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