commit def70ad6d72880f238f03d0994ab727ec11a3477
parent 642afeeca47fecf457d6201f1393cd29dcd4101b
Author: serge-sans-paille <sguelton@mozilla.com>
Date: Wed, 8 Oct 2025 14:03:55 +0000
Bug 1993115 - Cleanup mfbt/IntegerRange.h r=emilio
Use inline friend operator declaration, which in turns disable
comparison between iterators over integer of different types.
Also remove useless inclusion in the process.
Differential Revision: https://phabricator.services.mozilla.com/D267876
Diffstat:
3 files changed, 27 insertions(+), 68 deletions(-)
diff --git a/accessible/generic/HyperTextAccessible.cpp b/accessible/generic/HyperTextAccessible.cpp
@@ -33,7 +33,6 @@
#include "mozilla/Assertions.h"
#include "mozilla/EditorBase.h"
#include "mozilla/HTMLEditor.h"
-#include "mozilla/IntegerRange.h"
#include "mozilla/PresShell.h"
#include "mozilla/ScrollContainerFrame.h"
#include "mozilla/SelectionMovementUtils.h"
diff --git a/dom/canvas/SanitizeRenderer.cpp b/dom/canvas/SanitizeRenderer.cpp
@@ -7,7 +7,6 @@
#include <regex>
#include <string>
-#include "mozilla/IntegerRange.h"
#include "mozilla/gfx/Logging.h"
namespace mozilla {
diff --git a/mfbt/IntegerRange.h b/mfbt/IntegerRange.h
@@ -70,65 +70,35 @@ class IntegerIterator {
/* Comparison operators */
- template <typename IntType1, typename IntType2>
- friend bool operator==(const IntegerIterator<IntType1>& aIter1,
- const IntegerIterator<IntType2>& aIter2);
- template <typename IntType1, typename IntType2>
- friend bool operator!=(const IntegerIterator<IntType1>& aIter1,
- const IntegerIterator<IntType2>& aIter2);
- template <typename IntType1, typename IntType2>
- friend bool operator<(const IntegerIterator<IntType1>& aIter1,
- const IntegerIterator<IntType2>& aIter2);
- template <typename IntType1, typename IntType2>
- friend bool operator<=(const IntegerIterator<IntType1>& aIter1,
- const IntegerIterator<IntType2>& aIter2);
- template <typename IntType1, typename IntType2>
- friend bool operator>(const IntegerIterator<IntType1>& aIter1,
- const IntegerIterator<IntType2>& aIter2);
- template <typename IntType1, typename IntType2>
- friend bool operator>=(const IntegerIterator<IntType1>& aIter1,
- const IntegerIterator<IntType2>& aIter2);
+ friend bool operator==(const IntegerIterator<IntTypeT>& aIter1,
+ const IntegerIterator<IntTypeT>& aIter2) {
+ return aIter1.mCurrent == aIter2.mCurrent;
+ }
+ friend bool operator!=(const IntegerIterator<IntTypeT>& aIter1,
+ const IntegerIterator<IntTypeT>& aIter2) {
+ return aIter1.mCurrent != aIter2.mCurrent;
+ }
+ friend bool operator<(const IntegerIterator<IntTypeT>& aIter1,
+ const IntegerIterator<IntTypeT>& aIter2) {
+ return aIter1.mCurrent < aIter2.mCurrent;
+ }
+ friend bool operator<=(const IntegerIterator<IntTypeT>& aIter1,
+ const IntegerIterator<IntTypeT>& aIter2) {
+ return aIter1.mCurrent <= aIter2.mCurrent;
+ }
+ friend bool operator>(const IntegerIterator<IntTypeT>& aIter1,
+ const IntegerIterator<IntTypeT>& aIter2) {
+ return aIter1.mCurrent > aIter2.mCurrent;
+ }
+ friend bool operator>=(const IntegerIterator<IntTypeT>& aIter1,
+ const IntegerIterator<IntTypeT>& aIter2) {
+ return aIter1.mCurrent >= aIter2.mCurrent;
+ }
private:
IntTypeT mCurrent;
};
-template <typename IntType1, typename IntType2>
-bool operator==(const IntegerIterator<IntType1>& aIter1,
- const IntegerIterator<IntType2>& aIter2) {
- return aIter1.mCurrent == aIter2.mCurrent;
-}
-
-template <typename IntType1, typename IntType2>
-bool operator!=(const IntegerIterator<IntType1>& aIter1,
- const IntegerIterator<IntType2>& aIter2) {
- return aIter1.mCurrent != aIter2.mCurrent;
-}
-
-template <typename IntType1, typename IntType2>
-bool operator<(const IntegerIterator<IntType1>& aIter1,
- const IntegerIterator<IntType2>& aIter2) {
- return aIter1.mCurrent < aIter2.mCurrent;
-}
-
-template <typename IntType1, typename IntType2>
-bool operator<=(const IntegerIterator<IntType1>& aIter1,
- const IntegerIterator<IntType2>& aIter2) {
- return aIter1.mCurrent <= aIter2.mCurrent;
-}
-
-template <typename IntType1, typename IntType2>
-bool operator>(const IntegerIterator<IntType1>& aIter1,
- const IntegerIterator<IntType2>& aIter2) {
- return aIter1.mCurrent > aIter2.mCurrent;
-}
-
-template <typename IntType1, typename IntType2>
-bool operator>=(const IntegerIterator<IntType1>& aIter1,
- const IntegerIterator<IntType2>& aIter2) {
- return aIter1.mCurrent >= aIter2.mCurrent;
-}
-
template <typename IntTypeT>
class IntegerRange {
public:
@@ -157,23 +127,14 @@ class IntegerRange {
IntTypeT mEnd;
};
-template <typename T, bool = std::is_unsigned_v<T>>
-struct GeqZero {
- static bool isNonNegative(T t) { return t >= 0; }
-};
-
-template <typename T>
-struct GeqZero<T, true> {
- static bool isNonNegative(T t) { return true; }
-};
-
} // namespace detail
template <typename IntType>
detail::IntegerRange<IntType> IntegerRange(IntType aEnd) {
static_assert(std::is_integral_v<IntType>, "value must be integral");
- MOZ_ASSERT(detail::GeqZero<IntType>::isNonNegative(aEnd),
- "Should never have negative value here");
+ if constexpr (std::is_signed_v<IntType>) {
+ MOZ_ASSERT(aEnd >= 0, "Should never have negative value here");
+ }
return detail::IntegerRange<IntType>(aEnd);
}