[llvm] 2fab15d - Inline operator== and operator!= (#67958)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 5 05:31:35 PDT 2023
Author: Giulio Eulisse
Date: 2023-10-05T15:31:28+03:00
New Revision: 2fab15d8fd05da4ef6504ce0746b0420997289be
URL: https://github.com/llvm/llvm-project/commit/2fab15d8fd05da4ef6504ce0746b0420997289be
DIFF: https://github.com/llvm/llvm-project/commit/2fab15d8fd05da4ef6504ce0746b0420997289be.diff
LOG: Inline operator== and operator!= (#67958)
Avoid triggering -Wnon-template-friend on newer GCC.
---------
Co-authored-by: Richard Smith <richard at metafoo.co.uk>
Added:
Modified:
llvm/include/llvm/ADT/PagedVector.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/ADT/PagedVector.h b/llvm/include/llvm/ADT/PagedVector.h
index 667bece6d718385..3fcca6d82cb33a0 100644
--- a/llvm/include/llvm/ADT/PagedVector.h
+++ b/llvm/include/llvm/ADT/PagedVector.h
@@ -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.
///
More information about the llvm-commits
mailing list