[Libreoffice-commits] core.git: binaryurp/source

Stephan Bergmann sbergman at redhat.com
Fri Aug 19 06:35:31 UTC 2016


 binaryurp/source/binaryany.cxx |   31 +++++++++++++++++++++++++++++++
 binaryurp/source/binaryany.hxx |    4 ++++
 2 files changed, 35 insertions(+)

New commits:
commit 9bc591fa1e3723cee508e1484ad422fdef956d7d
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Fri Aug 19 08:35:03 2016 +0200

    cid#1371307: Move semantics for BinaryAny
    
    Change-Id: I30b8bb71f8a9e093183ee85484ccd694f3e1e10d

diff --git a/binaryurp/source/binaryany.cxx b/binaryurp/source/binaryany.cxx
index f6fffc0..a416376 100644
--- a/binaryurp/source/binaryany.cxx
+++ b/binaryurp/source/binaryany.cxx
@@ -20,6 +20,7 @@
 #include "sal/config.h"
 
 #include <cassert>
+#include <utility>
 
 #include "typelib/typeclass.h"
 #include "typelib/typedescription.hxx"
@@ -29,6 +30,26 @@
 
 namespace binaryurp {
 
+namespace {
+
+// Cf. com::sun::star::uno::detail::moveAnyInternals in
+// include/com/sun/star/uno/Any.hxx:
+void moveInternals(uno_Any & from, uno_Any & to) {
+    uno_any_construct(&to, nullptr, nullptr, nullptr);
+    std::swap(from.pType, to.pType);
+    std::swap(from.pData, to.pData);
+    std::swap(from.pReserved, to.pReserved);
+    if (to.pData == &from.pReserved) {
+        to.pData = &to.pReserved;
+    }
+    // This leaves to.pData (where "to" is now VOID) dangling to somewhere (cf.
+    // CONSTRUCT_EMPTY_ANY, cppu/source/uno/prim.hxx), but what's relevant is
+    // only that it isn't a nullptr (as e.g. >>= -> uno_type_assignData ->
+    // _assignData takes a null pSource to mean "construct a default value").
+}
+
+}
+
 BinaryAny::BinaryAny() throw () {
     uno_any_construct(&data_, nullptr, nullptr, nullptr);
 }
@@ -52,6 +73,10 @@ BinaryAny::BinaryAny(BinaryAny const & other) throw () {
     uno_type_any_construct(&data_, other.data_.pData, other.data_.pType, nullptr);
 }
 
+BinaryAny::BinaryAny(BinaryAny && other) throw () {
+    moveInternals(other.data_, data_);
+}
+
 BinaryAny::~BinaryAny() throw () {
     uno_any_destruct(&data_, nullptr);
 }
@@ -63,6 +88,12 @@ BinaryAny & BinaryAny::operator =(BinaryAny const & other) throw () {
     return *this;
 }
 
+BinaryAny & BinaryAny::operator =(BinaryAny && other) throw () {
+    uno_any_destruct(&data_, nullptr);
+    moveInternals(other.data_, data_);
+    return *this;
+}
+
 css::uno::TypeDescription BinaryAny::getType() const throw () {
     return css::uno::TypeDescription(data_.pType);
 }
diff --git a/binaryurp/source/binaryany.hxx b/binaryurp/source/binaryany.hxx
index 717216a..1faf484 100644
--- a/binaryurp/source/binaryany.hxx
+++ b/binaryurp/source/binaryany.hxx
@@ -43,10 +43,14 @@ public:
 
     BinaryAny(BinaryAny const & other) throw ();
 
+    BinaryAny(BinaryAny && other) throw ();
+
     ~BinaryAny() throw ();
 
     BinaryAny & operator =(BinaryAny const & other) throw ();
 
+    BinaryAny & operator =(BinaryAny && other) throw ();
+
     uno_Any& get() throw () { return data_; }
 
     com::sun::star::uno::TypeDescription getType() const throw ();


More information about the Libreoffice-commits mailing list