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

Inline operator== and operator!= #67958

Merged
merged 5 commits into from
Oct 5, 2023
Merged
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
48 changes: 23 additions & 25 deletions llvm/include/llvm/ADT/PagedVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,35 +209,33 @@ template <typename T, size_t PageSize = 1024 / sizeof(T)> class PagedVector {
return PagePtr[ElementIdx % PageSize];
}

friend bool operator==(MaterializedIterator const &LHS,
MaterializedIterator const &RHS);
friend bool operator!=(MaterializedIterator const &LHS,
MaterializedIterator const &RHS);
/// Equality operator.
friend bool operator==(const MaterializedIterator &LHS,
const MaterializedIterator &RHS) {
return LHS.equals(RHS);
}

[[nodiscard]] size_t getIndex() const { return ElementIdx; }
};

/// Equality operator.
friend bool operator==(MaterializedIterator const &LHS,
MaterializedIterator const &RHS) {
assert(LHS.PV == RHS.PV);
// Make sure we are comparing either end iterators or iterators pointing
// to materialized elements.
// It should not be possible to build two iterators pointing to non
// materialized elements.
assert(LHS.ElementIdx == LHS.PV->Size ||
(LHS.ElementIdx < LHS.PV->Size &&
LHS.PV->PageToDataPtrs[LHS.ElementIdx / PageSize]));
assert(RHS.ElementIdx == RHS.PV->Size ||
(RHS.ElementIdx < RHS.PV->Size &&
RHS.PV->PageToDataPtrs[RHS.ElementIdx / PageSize]));
return LHS.ElementIdx == RHS.ElementIdx;
}
friend bool operator!=(const MaterializedIterator &LHS,
const MaterializedIterator &RHS) {
return !(LHS == RHS);
}

friend bool operator!=(MaterializedIterator const &LHS,
MaterializedIterator const &RHS) {
return !(LHS == RHS);
}
private:
void verify() const {
assert(
ElementIdx == PV->Size ||
(ElementIdx < PV->Size && PV->PageToDataPtrs[ElementIdx / PageSize]));
}

bool equals(const MaterializedIterator &Other) const {
assert(PV == Other.PV);
verify();
Other.verify();
return ElementIdx == Other.ElementIdx;
}
};

/// Iterators over the materialized elements of the vector.
///
Expand Down