From 4552388e438f6cb84a734b663f148d4ae68d4ad2 Mon Sep 17 00:00:00 2001 From: AlePalu Date: Fri, 8 Mar 2024 18:46:27 +0100 Subject: [PATCH] non_owning_storage move semantic, solved pessimizing-move warning in binary_matrix --- fdaPDE/linear_algebra/binary_matrix.h | 4 ++-- fdaPDE/utils/type_erasure.h | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/fdaPDE/linear_algebra/binary_matrix.h b/fdaPDE/linear_algebra/binary_matrix.h index d0799e8e..274cf1ac 100644 --- a/fdaPDE/linear_algebra/binary_matrix.h +++ b/fdaPDE/linear_algebra/binary_matrix.h @@ -471,7 +471,7 @@ template class BinMtxBase { for (int j = 0; j < mtx.cols(); ++j) { if (!get().operator()(i, j)) masked_mtx(i, j) = 0; } - return std::move(masked_mtx); + return masked_mtx; } template SpMatrix select(const Eigen::SparseMatrixBase& mtx) const { @@ -482,7 +482,7 @@ template class BinMtxBase { for (typename SpMatrix::InnerIterator it(masked_mtx, k); it; ++it) { if (!get().operator()(it.row(), it.col())) { it.valueRef() = 0; } } - return std::move(masked_mtx); + return masked_mtx; } // block-repeat operation BinMtxBlockRepeatOp blk_repeat(int rep_row, int rep_col) const { diff --git a/fdaPDE/utils/type_erasure.h b/fdaPDE/utils/type_erasure.h index 36bc4a26..df31584c 100644 --- a/fdaPDE/utils/type_erasure.h +++ b/fdaPDE/utils/type_erasure.h @@ -116,6 +116,11 @@ struct non_owning_storage { ptr_ = other.ptr_; return *this; } + non_owning_storage(non_owning_storage&& other) : ptr_(std::exchange(other.ptr_, nullptr)) { } + non_owning_storage& operator=(non_owning_storage&& other) { + ptr_ = std::exchange(other.ptr_, nullptr); + return *this; + } }; struct heap_storage {