Browse Source

Merge pull request #100560 from Ivorforce/localvector-move-semantics

Add `LocalVector` move semantics (constructor and operator=).
Thaddeus Crews 7 months ago
parent
commit
0b01f3cc14
1 changed files with 30 additions and 0 deletions
  1. 30 0
      core/templates/local_vector.h

+ 30 - 0
core/templates/local_vector.h

@@ -326,6 +326,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++) {
@@ -338,6 +348,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<T> &&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) {