]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Changed the vector move ctor/assignment operator not to use swap
authordanshapero <shapero.daniel@gmail.com>
Mon, 11 Apr 2016 23:25:22 +0000 (16:25 -0700)
committerdanshapero <shapero.daniel@gmail.com>
Wed, 13 Apr 2016 19:03:02 +0000 (12:03 -0700)
include/deal.II/lac/vector.h
include/deal.II/lac/vector.templates.h
tests/lac/vector_move_operations.with_cxx11=on.output

index 37543264502e6b2b14c4fd4070ed3463fbac9eb4..e507c90ca8459481e837ad907d98521de8c503dc 100644 (file)
@@ -347,8 +347,9 @@ public:
 
 #ifdef DEAL_II_WITH_CXX11
   /**
-   * Move the given vector. This operator replaces the present vector with @p
-   * v by efficiently swapping the internal data structures.
+   * Move the given vector. This operator replaces the present vector with
+   * the internal data of the vector @p v and resets @p v to the state it would
+   * have after being newly default-constructed.
    *
    * @note This operator is only available if deal.II is configured with C++11
    * support.
@@ -1128,7 +1129,17 @@ inline
 Vector<Number> &
 Vector<Number>::operator= (Vector<Number> &&v)
 {
-  swap(v);
+  Subscriptor::operator=(std::move(v));
+
+  if (val) deallocate();
+
+  vec_size = v.vec_size;
+  max_vec_size = v.max_vec_size;
+  val = v.val;
+
+  v.vec_size = 0;
+  v.max_vec_size = 0;
+  v.val = nullptr;
 
   return *this;
 }
index 3bd2faca6ed3a2e24307ae63237c3aa601a30993..24f0416fa94a40a1bd290725c42c56d6c3d552f3 100644 (file)
@@ -650,12 +650,14 @@ Vector<Number>::Vector (const Vector<Number> &v)
 template <typename Number>
 Vector<Number>::Vector (Vector<Number> &&v)
   :
-  Subscriptor(),
-  vec_size(0),
-  max_vec_size(0),
-  val(0)
+  Subscriptor(std::move(v)),
+  vec_size(v.vec_size),
+  max_vec_size(v.max_vec_size),
+  val(v.val)
 {
-  swap(v);
+  v.vec_size = 0;
+  v.max_vec_size = 0;
+  v.val = nullptr;
 }
 #endif
 
index 2bd7dd57de3807b2090b4b564c92c8a61160bdaa..25f8614359f9b58d739ec2c0e2a42be56d8a2196 100644 (file)
@@ -5,6 +5,6 @@ DEAL::vector:          1.00000 2.00000 3.00000 4.00000 5.00000 6.00000 7.00000 8
 DEAL::copy assignment: 1.00000 2.00000 3.00000 4.00000 5.00000 6.00000 7.00000 8.00000 9.00000 10.0000 
 DEAL::old object:      1.00000 2.00000 3.00000 4.00000 5.00000 6.00000 7.00000 8.00000 9.00000 10.0000 
 DEAL::move assignment: 1.00000 2.00000 3.00000 4.00000 5.00000 6.00000 7.00000 8.00000 9.00000 10.0000 
-DEAL::old object size: 10
+DEAL::old object size: 0
 DEAL::move assignment: 1.00000 2.00000 3.00000 4.00000 5.00000 6.00000 7.00000 8.00000 9.00000 10.0000 
 DEAL::old object size: 0

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.