BRegion: add move construction and assignment support

GCC 2 support is also provided with `MoveFrom` method.

Change-Id: Ibd062f501fdeb5538ade6c84dcafb61cff70cc32
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8529
Tested-by: Commit checker robot <[email protected]>
Reviewed-by: waddlesplash <[email protected]>
This commit is contained in:
X512
2024-11-11 16:56:19 +00:00
committed by waddlesplash
parent 1e3e4210de
commit 80fcf2df19
2 changed files with 55 additions and 0 deletions
+7
View File
@@ -29,13 +29,20 @@ public:
BRegion(); BRegion();
BRegion(const BRegion& other); BRegion(const BRegion& other);
BRegion(const BRect rect); BRegion(const BRect rect);
#if defined(__cplusplus) && __cplusplus >= 201103L
BRegion(BRegion&& other);
#endif
virtual ~BRegion(); virtual ~BRegion();
BRegion& operator=(const BRegion& other); BRegion& operator=(const BRegion& other);
#if defined(__cplusplus) && __cplusplus >= 201103L
BRegion& operator=(BRegion&& other);
#endif
bool operator==(const BRegion& other) const; bool operator==(const BRegion& other) const;
void Set(BRect rect); void Set(BRect rect);
void Set(clipping_rect clipping); void Set(clipping_rect clipping);
void MoveFrom(BRegion& other);
BRect Frame() const; BRect Frame() const;
clipping_rect FrameInt() const; clipping_rect FrameInt() const;
+48
View File
@@ -59,6 +59,19 @@ BRegion::BRegion(const BRect rect)
} }
#if defined(__cplusplus) && __cplusplus >= 201103L
BRegion::BRegion(BRegion&& other)
:
fCount(0),
fDataSize(0),
fBounds((clipping_rect){ 0, 0, 0, 0 }),
fData(NULL)
{
MoveFrom(other);
}
#endif
// NOTE: private constructor // NOTE: private constructor
BRegion::BRegion(const clipping_rect& clipping) BRegion::BRegion(const clipping_rect& clipping)
: :
@@ -95,6 +108,17 @@ BRegion::operator=(const BRegion& other)
} }
#if defined(__cplusplus) && __cplusplus >= 201103L
BRegion&
BRegion::operator=(BRegion&& other)
{
MoveFrom(other);
return *this;
}
#endif
bool bool
BRegion::operator==(const BRegion& other) const BRegion::operator==(const BRegion& other) const
{ {
@@ -128,6 +152,30 @@ BRegion::Set(clipping_rect clipping)
} }
void
BRegion::MoveFrom(BRegion& other)
{
if (other.CountRects() <= 0) {
MakeEmpty();
return;
}
if (other.CountRects() == 1) {
Set(other.FrameInt());
other.MakeEmpty();
return;
}
fCount = other.fCount;
fDataSize = other.fDataSize;
fBounds = other.fBounds;
fData = other.fData;
other.fCount = 0;
other.fDataSize = 0;
other.fBounds = (clipping_rect){ 0, 0, 0, 0 };
other.fData = NULL;
}
BRect BRect
BRegion::Frame() const BRegion::Frame() const
{ {