From 3564e7c2314c82d3e9b2a822206c61d2212165d6 Mon Sep 17 00:00:00 2001 From: Lukas Tenbrink Date: Wed, 18 Dec 2024 16:09:54 +0100 Subject: [PATCH] Add `LocalVector` move semantics (constructor and operator=). --- core/templates/local_vector.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/core/templates/local_vector.h b/core/templates/local_vector.h index c281d70d928..087e2e92f08 100644 --- a/core/templates/local_vector.h +++ b/core/templates/local_vector.h @@ -322,6 +322,16 @@ public: data[i] = p_from.data[i]; } } + _FORCE_INLINE_ LocalVector(LocalVector &&p_from) { + data = p_from.data; + count = p_from.count; + capacity = p_from.capacity; + + p_from.data = nullptr; + p_from.count = 0; + p_from.capacity = 0; + } + inline void operator=(const LocalVector &p_from) { resize(p_from.size()); for (U i = 0; i < p_from.count; i++) { @@ -334,6 +344,26 @@ public: data[i] = p_from[i]; } } + inline void operator=(LocalVector &&p_from) { + if (unlikely(this == &p_from)) { + return; + } + reset(); + + data = p_from.data; + count = p_from.count; + capacity = p_from.capacity; + + p_from.data = nullptr; + p_from.count = 0; + p_from.capacity = 0; + } + inline void operator=(Vector &&p_from) { + resize(p_from.size()); + for (U i = 0; i < count; i++) { + data[i] = std::move(p_from[i]); + } + } _FORCE_INLINE_ ~LocalVector() { if (data) {