Skip to content

Commit

Permalink
Inline operator== and operator!= (#67958)
Browse files Browse the repository at this point in the history
Avoid triggering -Wnon-template-friend on newer GCC.

---------

Co-authored-by: Richard Smith <[email protected]>
  • Loading branch information
ktf and zygoloid authored Oct 5, 2023
1 parent 96dd50e commit 2fab15d
Showing 1 changed file with 23 additions and 25 deletions.
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

0 comments on commit 2fab15d

Please sign in to comment.