From f9471f341d5ec88022e9eeed71a1cb8895db6e8f Mon Sep 17 00:00:00 2001 From: Teon Banek Date: Wed, 15 May 2019 13:48:53 +0200 Subject: [PATCH] Fix move assign of MonotonicBufferResource Summary: I was a bit stupid and thought I can use `std::swap`, while `std::swap` is implemented in terms of move itself. Reviewers: mtomic, mferencevic Reviewed By: mtomic Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D2054 --- src/utils/memory.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/utils/memory.cpp b/src/utils/memory.cpp index b8e4edca6..64b687416 100644 --- a/src/utils/memory.cpp +++ b/src/utils/memory.cpp @@ -52,8 +52,14 @@ MonotonicBufferResource::MonotonicBufferResource( MonotonicBufferResource &MonotonicBufferResource::operator=( MonotonicBufferResource &&other) noexcept { - MonotonicBufferResource tmp(std::move(other)); - std::swap(*this, tmp); + if (this == &other) return *this; + Release(); + memory_ = other.memory_; + current_buffer_ = other.current_buffer_; + initial_size_ = other.initial_size_; + allocated_ = other.allocated_; + other.current_buffer_ = nullptr; + other.allocated_ = 0U; return *this; }