[llvm] Inline operator== and operator!= (PR #67958)
Richard Smith via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 3 00:22:15 PDT 2023
================
@@ -209,36 +209,31 @@ template <typename T, size_t PageSize = 1024 / sizeof(T)> class PagedVector {
return PagePtr[ElementIdx % PageSize];
}
+ /// Equality operator.
friend bool operator==(MaterializedIterator const &LHS,
- MaterializedIterator const &RHS);
+ 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;
+ }
----------------
zygoloid wrote:
```suggestion
return LHS.equals(RHS);
}
private:
void verify() {
assert(ElementIdx == PV->Size ||
(ElementIdx < PV->Size &&
PV->PageToDataPtrs[ElementIdx / PageSize]));
}
bool equals(const MaterializedIterator &Other) {
assert(PV == Other.PV);
verify();
Other.verify();
return ElementIdx == Other.ElementIdx;
}
```
Something like this seems like it should work and avoid the MSVC and GCC errors and the GCC warning.
https://github.com/llvm/llvm-project/pull/67958
More information about the llvm-commits
mailing list