From: danshapero Date: Mon, 11 Apr 2016 23:25:22 +0000 (-0700) Subject: Changed the vector move ctor/assignment operator not to use swap X-Git-Tag: v8.5.0-rc1~1106^2~3 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c38c657e32c35c20ab661dd0d09e6d7d3729e1b3;p=dealii.git Changed the vector move ctor/assignment operator not to use swap --- diff --git a/include/deal.II/lac/vector.h b/include/deal.II/lac/vector.h index 3754326450..e507c90ca8 100644 --- a/include/deal.II/lac/vector.h +++ b/include/deal.II/lac/vector.h @@ -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 & Vector::operator= (Vector &&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; } diff --git a/include/deal.II/lac/vector.templates.h b/include/deal.II/lac/vector.templates.h index 3bd2faca6e..24f0416fa9 100644 --- a/include/deal.II/lac/vector.templates.h +++ b/include/deal.II/lac/vector.templates.h @@ -650,12 +650,14 @@ Vector::Vector (const Vector &v) template Vector::Vector (Vector &&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 diff --git a/tests/lac/vector_move_operations.with_cxx11=on.output b/tests/lac/vector_move_operations.with_cxx11=on.output index 2bd7dd57de..25f8614359 100644 --- a/tests/lac/vector_move_operations.with_cxx11=on.output +++ b/tests/lac/vector_move_operations.with_cxx11=on.output @@ -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