diff --git a/llvm/include/llvm/ADT/PagedVector.h b/llvm/include/llvm/ADT/PagedVector.h index 667bece6d7183..3fcca6d82cb33 100644 --- a/llvm/include/llvm/ADT/PagedVector.h +++ b/llvm/include/llvm/ADT/PagedVector.h @@ -209,35 +209,33 @@ template 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. ///