From 80fcf2df1901d31d6cb152ef88ef75125c5915d4 Mon Sep 17 00:00:00 2001 From: X512 Date: Sat, 9 Nov 2024 21:17:34 +0900 Subject: [PATCH] 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 Reviewed-by: waddlesplash --- headers/os/interface/Region.h | 7 +++++ src/kits/interface/Region.cpp | 48 +++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/headers/os/interface/Region.h b/headers/os/interface/Region.h index b5e729004d..a8ee4a3d63 100644 --- a/headers/os/interface/Region.h +++ b/headers/os/interface/Region.h @@ -29,13 +29,20 @@ public: BRegion(); BRegion(const BRegion& other); BRegion(const BRect rect); +#if defined(__cplusplus) && __cplusplus >= 201103L + BRegion(BRegion&& other); +#endif virtual ~BRegion(); BRegion& operator=(const BRegion& other); +#if defined(__cplusplus) && __cplusplus >= 201103L + BRegion& operator=(BRegion&& other); +#endif bool operator==(const BRegion& other) const; void Set(BRect rect); void Set(clipping_rect clipping); + void MoveFrom(BRegion& other); BRect Frame() const; clipping_rect FrameInt() const; diff --git a/src/kits/interface/Region.cpp b/src/kits/interface/Region.cpp index b05f3c6649..ee731e9357 100644 --- a/src/kits/interface/Region.cpp +++ b/src/kits/interface/Region.cpp @@ -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 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 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 BRegion::Frame() const {