[llvm] Inline operator== and operator!= (PR #67958)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 2 01:32:15 PDT 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-adt
<details>
<summary>Changes</summary>
Avoid triggering -Wnon-template-friend on newer GCC.
---
Full diff: https://github.com/llvm/llvm-project/pull/67958.diff
1 Files Affected:
- (modified) llvm/include/llvm/ADT/PagedVector.h (+19-24)
``````````diff
diff --git a/llvm/include/llvm/ADT/PagedVector.h b/llvm/include/llvm/ADT/PagedVector.h
index 667bece6d718385..c96e0b20e2d33d7 100644
--- a/llvm/include/llvm/ADT/PagedVector.h
+++ b/llvm/include/llvm/ADT/PagedVector.h
@@ -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;
+ }
+
friend bool operator!=(MaterializedIterator const &LHS,
- MaterializedIterator const &RHS);
+ MaterializedIterator const &RHS) {
+ return !(LHS == 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!=(MaterializedIterator const &LHS,
- MaterializedIterator const &RHS) {
- return !(LHS == RHS);
- }
-
/// Iterators over the materialized elements of the vector.
///
/// This includes all the elements belonging to allocated pages,
``````````
</details>
https://github.com/llvm/llvm-project/pull/67958
More information about the llvm-commits
mailing list