From 1c6f3a74e1121b0402042743e2e0f392c5e20961 Mon Sep 17 00:00:00 2001 From: q66 Date: Tue, 16 Jun 2015 20:02:52 +0100 Subject: [PATCH] follow allocator propagation on swap + do not free memory unless necessary --- octa/vector.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/octa/vector.h b/octa/vector.h index 7169699..1990416 100644 --- a/octa/vector.h +++ b/octa/vector.h @@ -128,7 +128,7 @@ public: } Vector(Vector &&v, const A &a): p_buf(nullptr, a) { - if (!(a == v.p_buf.second())) { + if (a != v.p_buf.second()) { reserve(v.p_cap); p_len = v.p_len; if (octa::IsPod()) { @@ -193,8 +193,10 @@ public: if (this == &v) return *this; clear(); if (octa::AllocatorPropagateOnContainerCopyAssignment::value) { - octa::allocator_deallocate(p_buf.second(), p_buf.first(), p_cap); - p_cap = 0; + if (p_buf.second() != v.p_buf.second()) { + octa::allocator_deallocate(p_buf.second(), p_buf.first(), p_cap); + p_cap = 0; + } p_buf.second() = v.p_buf.second(); } reserve(v.p_cap); @@ -400,7 +402,9 @@ public: void swap(Vector &v) { octa::swap(p_len, v.p_len); octa::swap(p_cap, v.p_cap); - p_buf.swap(v.p_buf); + octa::swap(p_buf.first(), v.p_buf.first()); + if (octa::AllocatorPropagateOnContainerSwap::value) + octa::swap(p_buf.second(), v.p_buf.second()); } A get_allocator() const {