From 724e44d5a0565dd620e38dbf0edd0fd9825ebd59 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Mon, 4 Aug 2025 13:04:35 +0100 Subject: [PATCH] Move assignment operators for some hot-path classes. --- libs/core/include/core/utf8.h | 23 +++++++++++++++++++ .../include/geometry/shape_line_chain.h | 20 ++++++++++++++++ libs/kimath/include/geometry/shape_poly_set.h | 18 +++++++++++++++ 3 files changed, 61 insertions(+) diff --git a/libs/core/include/core/utf8.h b/libs/core/include/core/utf8.h index 06d0268b9d..8ace934491 100644 --- a/libs/core/include/core/utf8.h +++ b/libs/core/include/core/utf8.h @@ -91,6 +91,12 @@ public: MAYBE_VERIFY_UTF8( c_str() ); } + UTF8( const UTF8& o ) : + m_s( o.m_s ) + { + MAYBE_VERIFY_UTF8( c_str() ); + } + UTF8() { } @@ -178,6 +184,23 @@ public: return *this; } + UTF8& operator=( const UTF8& aOther ) + { + m_s = aOther.m_s; + MAYBE_VERIFY_UTF8( c_str() ); + return *this; + } + + // Move assignment operator + UTF8& operator=( UTF8&& aOther ) noexcept + { + if (this != &aOther) + m_s = std::move( aOther.m_s ); + + MAYBE_VERIFY_UTF8( c_str() ); + return *this; + } + // a substring of a UTF8 is not necessarily a UTF8 if a multibyte character // was split, so return std::string not UTF8 std::string substr( size_t pos = 0, size_t len = npos ) const diff --git a/libs/kimath/include/geometry/shape_line_chain.h b/libs/kimath/include/geometry/shape_line_chain.h index a45c8ab9c5..af13ad0704 100644 --- a/libs/kimath/include/geometry/shape_line_chain.h +++ b/libs/kimath/include/geometry/shape_line_chain.h @@ -250,6 +250,26 @@ public: SHAPE_LINE_CHAIN& operator=( const SHAPE_LINE_CHAIN& ) = default; + // Move assignment operator + SHAPE_LINE_CHAIN& operator=( SHAPE_LINE_CHAIN&& aOther ) noexcept + { + if (this != &aOther) + { + SHAPE_LINE_CHAIN_BASE::operator=( aOther ); + + m_points = std::move( aOther.m_points ); + m_shapes = std::move( aOther.m_shapes ); + m_arcs = std::move( aOther.m_arcs ); + + m_accuracy = aOther.m_accuracy; + m_closed = aOther.m_closed; + m_width = aOther.m_width; + m_bbox = aOther.m_bbox; + } + + return *this; + } + SHAPE* Clone() const override; /** diff --git a/libs/kimath/include/geometry/shape_poly_set.h b/libs/kimath/include/geometry/shape_poly_set.h index 378c5ddb0e..a5540037a3 100644 --- a/libs/kimath/include/geometry/shape_poly_set.h +++ b/libs/kimath/include/geometry/shape_poly_set.h @@ -535,6 +535,24 @@ public: SHAPE_POLY_SET& operator=( const SHAPE_POLY_SET& aOther ); + // Move assignment operator + SHAPE_POLY_SET& operator=( SHAPE_POLY_SET&& aOther ) noexcept + { + if (this != &aOther) + { + SHAPE::operator=( aOther ); + + m_polys = std::move( aOther.m_polys ); + m_triangulatedPolys = std::move( aOther.m_triangulatedPolys ); + + m_hash = aOther.m_hash; + m_hashValid = aOther.m_hashValid; + m_triangulationValid.store( aOther.m_triangulationValid ); + } + + return *this; + } + /** * Build a polygon triangulation, needed to draw a polygon on OpenGL and in some * other calculations