Bug 2069594. Give nsRect the default copy constructor so the compiler knows it is trivially copyable. r=layout-reviewers,emilio

On some ABIs this means that it can be passed and returned in a register instead of in memory.

Differential Revision: https://phabricator.services.mozilla.com/D323836
This commit is contained in:
Timothy Nikkel
2026-09-06 09:16:37 +00:00
committed by tnikkel@mozilla.com
parent 162466af90
commit 66b9023dea
2 changed files with 14 additions and 15 deletions
+13 -15
View File
@@ -7,15 +7,15 @@
#include <stdint.h> // for int32_t, int64_t
#include <algorithm> // for min/max
#include <algorithm> // for min/max
#include <type_traits> // for is_trivially_copyable_v
#include "mozilla/Likely.h" // for MOZ_UNLIKELY
#include "mozilla/gfx/BaseRect.h"
#include "mozilla/gfx/Rect.h"
#include "nsCoord.h" // for nscoord, etc
#include "nsISupports.h" // for MOZ_COUNT_CTOR, etc
#include "nsPoint.h" // for nsIntPoint, nsPoint
#include "nsSize.h" // for IntSize, nsSize
#include "nsCoord.h" // for nscoord, etc
#include "nsPoint.h" // for nsIntPoint, nsPoint
#include "nsSize.h" // for IntSize, nsSize
#if !defined(ANDROID) && (defined(__SSE2__) || defined(_M_X64) || \
(defined(_M_IX86_FP) && _M_IX86_FP >= 2))
@@ -38,19 +38,13 @@ struct nsRect : public mozilla::gfx::BaseRect<nscoord, nsRect, nsPoint, nsSize,
Super;
// Constructors
nsRect() { MOZ_COUNT_CTOR(nsRect); }
nsRect(const nsRect& aRect) : Super(aRect) { MOZ_COUNT_CTOR(nsRect); }
nsRect(const nsPoint& aOrigin, const nsSize& aSize) : Super(aOrigin, aSize) {
MOZ_COUNT_CTOR(nsRect);
}
nsRect() = default;
nsRect(const nsRect& aRect) = default;
nsRect(const nsPoint& aOrigin, const nsSize& aSize) : Super(aOrigin, aSize) {}
nsRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight)
: Super(aX, aY, aWidth, aHeight) {
MOZ_COUNT_CTOR(nsRect);
}
: Super(aX, aY, aWidth, aHeight) {}
nsRect& operator=(const nsRect&) = default;
MOZ_COUNTED_DTOR(nsRect)
// We have saturating versions of all the Union methods. These avoid
// overflowing nscoord values in the 'width' and 'height' fields by
// clamping the width and height values to nscoord_MAX if necessary.
@@ -172,6 +166,10 @@ struct nsRect : public mozilla::gfx::BaseRect<nscoord, nsRect, nsPoint, nsSize,
}
};
static_assert(std::is_trivially_copyable_v<nsRect>,
"nsRect must stay trivially copyable so that it is passed and "
"returned in registers");
/*
* App Unit/Pixel conversions
*/
+1
View File
@@ -8,6 +8,7 @@
#include "mozilla/AlreadyAddRefed.h"
#include "mozilla/gfx/Matrix.h"
#include "nsRect.h"
#include "nsStringFwd.h"
class nsIWidget;
class nsPIDOMWindowOuter;