From ad321f50d91937a319f29ebab89b9509acc9b51e Mon Sep 17 00:00:00 2001 From: Moonchild Date: Fri, 3 Nov 2023 00:34:37 +0100 Subject: Issue #2342: Use [[nodiscard]] in /gfx and /layout --- gfx/2d/BaseRect.h | 12 ++++++------ gfx/2d/Rect.h | 4 ++-- gfx/src/nsPoint.h | 6 +++--- gfx/src/nsRect.h | 26 +++++++++++++------------- gfx/src/nsRegion.h | 4 ++-- gfx/src/nsSize.h | 2 +- 6 files changed, 27 insertions(+), 27 deletions(-) (limited to 'gfx') diff --git a/gfx/2d/BaseRect.h b/gfx/2d/BaseRect.h index a4e5e4c1d0..7f1590060d 100644 --- a/gfx/2d/BaseRect.h +++ b/gfx/2d/BaseRect.h @@ -111,7 +111,7 @@ struct BaseRect { // Intersection with an empty Rect may not produce an empty Rect if overflow // occurs. e.g. {INT_MIN, 0, 0, 20} Intersect { 5000, 0, 500, 20 } gives: // the non-emtpy {5000, 0, 500, 20 } instead of {5000, 0, 0, 0} - MOZ_MUST_USE Sub Intersect(const Sub& aRect) const + [[nodiscard]] Sub Intersect(const Sub& aRect) const { Sub result; result.x = std::max(x, aRect.x); @@ -127,7 +127,7 @@ struct BaseRect { // better. This comes at a tiny cost in performance. // e.g. {INT_MIN, 0, 0, 20} Intersect { 5000, 0, 500, 20 } gives: // {5000, 0, 0, 0} - MOZ_MUST_USE Sub SafeIntersect(const Sub& aRect) const + [[nodiscard]] Sub SafeIntersect(const Sub& aRect) const { Sub result; result.x = std::max(x, aRect.x); @@ -161,7 +161,7 @@ struct BaseRect { // If both rectangles are empty, returns this. // WARNING! This is not safe against overflow, prefer using SafeUnion instead // when dealing with int-based rects. - MOZ_MUST_USE Sub Union(const Sub& aRect) const + [[nodiscard]] Sub Union(const Sub& aRect) const { if (IsEmpty()) { return aRect; @@ -176,7 +176,7 @@ struct BaseRect { // Thus, empty input rectangles are allowed to affect the result. // WARNING! This is not safe against overflow, prefer using SafeUnionEdges // instead when dealing with int-based rects. - MOZ_MUST_USE Sub UnionEdges(const Sub& aRect) const + [[nodiscard]] Sub UnionEdges(const Sub& aRect) const { Sub result; result.x = std::min(x, aRect.x); @@ -588,7 +588,7 @@ struct BaseRect { * Clamp aPoint to this rectangle. It is allowed to end up on any * edge of the rectangle. */ - MOZ_MUST_USE Point ClampPoint(const Point& aPoint) const + [[nodiscard]] Point ClampPoint(const Point& aPoint) const { return Point(std::max(x, std::min(XMost(), aPoint.x)), std::max(y, std::min(YMost(), aPoint.y))); @@ -599,7 +599,7 @@ struct BaseRect { * aRect then the dimensions that don't fit will be shrunk so that they * do fit. The resulting rect is returned. */ - MOZ_MUST_USE Sub MoveInsideAndClamp(const Sub& aRect) const + [[nodiscard]] Sub MoveInsideAndClamp(const Sub& aRect) const { Sub rect(std::max(aRect.x, x), std::max(aRect.y, y), diff --git a/gfx/2d/Rect.h b/gfx/2d/Rect.h index 942cb200db..d17b802434 100644 --- a/gfx/2d/Rect.h +++ b/gfx/2d/Rect.h @@ -166,7 +166,7 @@ struct IntRectTyped : // Same as Union(), but in the cases where aRect is non-empty, the union is // done while guarding against overflow. If an overflow is detected, Nothing // is returned. - MOZ_MUST_USE Maybe SafeUnion(const Self& aRect) const + [[nodiscard]] Maybe SafeUnion(const Self& aRect) const { if (this->IsEmpty()) { return aRect.Overflows() ? Nothing() : Some(aRect); @@ -179,7 +179,7 @@ struct IntRectTyped : // Same as UnionEdges, but guards against overflow. If an overflow is detected, // Nothing is returned. - MOZ_MUST_USE Maybe SafeUnionEdges(const Self& aRect) const + [[nodiscard]] Maybe SafeUnionEdges(const Self& aRect) const { if (this->Overflows() || aRect.Overflows()) { return Nothing(); diff --git a/gfx/src/nsPoint.h b/gfx/src/nsPoint.h index b377eb5a56..3c406e5a61 100644 --- a/gfx/src/nsPoint.h +++ b/gfx/src/nsPoint.h @@ -35,12 +35,12 @@ struct nsPoint : public mozilla::gfx::BasePoint { * @param aFromAPP the APP to scale from * @param aToAPP the APP to scale to */ - MOZ_MUST_USE inline nsPoint + [[nodiscard]] inline nsPoint ScaleToOtherAppUnits(int32_t aFromAPP, int32_t aToAPP) const; - MOZ_MUST_USE inline nsPoint + [[nodiscard]] inline nsPoint RemoveResolution(const float resolution) const; - MOZ_MUST_USE inline nsPoint + [[nodiscard]] inline nsPoint ApplyResolution(const float resolution) const; }; diff --git a/gfx/src/nsRect.h b/gfx/src/nsRect.h index 267f5849cb..403d3c06b2 100644 --- a/gfx/src/nsRect.h +++ b/gfx/src/nsRect.h @@ -56,7 +56,7 @@ struct nsRect : // overflowing nscoord values in the 'width' and 'height' fields by // clamping the width and height values to nscoord_MAX if necessary. - MOZ_MUST_USE nsRect SaturatingUnion(const nsRect& aRect) const + [[nodiscard]] nsRect SaturatingUnion(const nsRect& aRect) const { if (IsEmpty()) { return aRect; @@ -67,7 +67,7 @@ struct nsRect : } } - MOZ_MUST_USE nsRect SaturatingUnionEdges(const nsRect& aRect) const + [[nodiscard]] nsRect SaturatingUnionEdges(const nsRect& aRect) const { #ifdef NS_COORD_IS_FLOAT return UnionEdges(aRect); @@ -102,7 +102,7 @@ struct nsRect : #ifndef NS_COORD_IS_FLOAT // Make all nsRect Union methods be saturating. - MOZ_MUST_USE nsRect UnionEdges(const nsRect& aRect) const + [[nodiscard]] nsRect UnionEdges(const nsRect& aRect) const { return SaturatingUnionEdges(aRect); } @@ -110,7 +110,7 @@ struct nsRect : { *this = aRect1.UnionEdges(aRect2); } - MOZ_MUST_USE nsRect Union(const nsRect& aRect) const + [[nodiscard]] nsRect Union(const nsRect& aRect) const { return SaturatingUnion(aRect); } @@ -141,32 +141,32 @@ struct nsRect : * @param aToAPP the APP to scale to * @note this can turn an empty rectangle into a non-empty rectangle */ - MOZ_MUST_USE inline nsRect + [[nodiscard]] inline nsRect ScaleToOtherAppUnitsRoundOut(int32_t aFromAPP, int32_t aToAPP) const; - MOZ_MUST_USE inline nsRect + [[nodiscard]] inline nsRect ScaleToOtherAppUnitsRoundIn(int32_t aFromAPP, int32_t aToAPP) const; - MOZ_MUST_USE inline mozilla::gfx::IntRect + [[nodiscard]] inline mozilla::gfx::IntRect ScaleToNearestPixels(float aXScale, float aYScale, nscoord aAppUnitsPerPixel) const; - MOZ_MUST_USE inline mozilla::gfx::IntRect + [[nodiscard]] inline mozilla::gfx::IntRect ToNearestPixels(nscoord aAppUnitsPerPixel) const; // Note: this can turn an empty rectangle into a non-empty rectangle - MOZ_MUST_USE inline mozilla::gfx::IntRect + [[nodiscard]] inline mozilla::gfx::IntRect ScaleToOutsidePixels(float aXScale, float aYScale, nscoord aAppUnitsPerPixel) const; // Note: this can turn an empty rectangle into a non-empty rectangle - MOZ_MUST_USE inline mozilla::gfx::IntRect + [[nodiscard]] inline mozilla::gfx::IntRect ToOutsidePixels(nscoord aAppUnitsPerPixel) const; - MOZ_MUST_USE inline mozilla::gfx::IntRect + [[nodiscard]] inline mozilla::gfx::IntRect ScaleToInsidePixels(float aXScale, float aYScale, nscoord aAppUnitsPerPixel) const; - MOZ_MUST_USE inline mozilla::gfx::IntRect + [[nodiscard]] inline mozilla::gfx::IntRect ToInsidePixels(nscoord aAppUnitsPerPixel) const; // This is here only to keep IPDL-generated code happy. DO NOT USE. @@ -175,7 +175,7 @@ struct nsRect : return IsEqualEdges(aRect); } - MOZ_MUST_USE inline nsRect RemoveResolution(const float aResolution) const; + [[nodiscard]] inline nsRect RemoveResolution(const float aResolution) const; }; /* diff --git a/gfx/src/nsRegion.h b/gfx/src/nsRegion.h index e4ad5fc8a0..143be356e6 100644 --- a/gfx/src/nsRegion.h +++ b/gfx/src/nsRegion.h @@ -296,9 +296,9 @@ public: * @param aToAPP the APP to scale to * @note this can turn an empty region into a non-empty region */ - MOZ_MUST_USE nsRegion + [[nodiscard]] nsRegion ScaleToOtherAppUnitsRoundOut (int32_t aFromAPP, int32_t aToAPP) const; - MOZ_MUST_USE nsRegion + [[nodiscard]] nsRegion ScaleToOtherAppUnitsRoundIn (int32_t aFromAPP, int32_t aToAPP) const; nsRegion& ScaleRoundOut(float aXScale, float aYScale); nsRegion& ScaleInverseRoundOut(float aXScale, float aYScale); diff --git a/gfx/src/nsSize.h b/gfx/src/nsSize.h index f27c478f96..bb1505a2c2 100644 --- a/gfx/src/nsSize.h +++ b/gfx/src/nsSize.h @@ -30,7 +30,7 @@ struct nsSize : public mozilla::gfx::BaseSize { * @param aFromAPP the APP to scale from * @param aToAPP the APP to scale to */ - MOZ_MUST_USE inline nsSize + [[nodiscard]] inline nsSize ScaleToOtherAppUnits(int32_t aFromAPP, int32_t aToAPP) const; }; -- cgit v1.2.3