Skip to content

Commit 0b01f3c

Browse files
committed
Merge pull request #100560 from Ivorforce/localvector-move-semantics
Add `LocalVector` move semantics (constructor and operator=).
2 parents 4665faa + 3564e7c commit 0b01f3c

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

core/templates/local_vector.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,16 @@ class LocalVector {
326326
data[i] = p_from.data[i];
327327
}
328328
}
329+
_FORCE_INLINE_ LocalVector(LocalVector &&p_from) {
330+
data = p_from.data;
331+
count = p_from.count;
332+
capacity = p_from.capacity;
333+
334+
p_from.data = nullptr;
335+
p_from.count = 0;
336+
p_from.capacity = 0;
337+
}
338+
329339
inline void operator=(const LocalVector &p_from) {
330340
resize(p_from.size());
331341
for (U i = 0; i < p_from.count; i++) {
@@ -338,6 +348,26 @@ class LocalVector {
338348
data[i] = p_from[i];
339349
}
340350
}
351+
inline void operator=(LocalVector &&p_from) {
352+
if (unlikely(this == &p_from)) {
353+
return;
354+
}
355+
reset();
356+
357+
data = p_from.data;
358+
count = p_from.count;
359+
capacity = p_from.capacity;
360+
361+
p_from.data = nullptr;
362+
p_from.count = 0;
363+
p_from.capacity = 0;
364+
}
365+
inline void operator=(Vector<T> &&p_from) {
366+
resize(p_from.size());
367+
for (U i = 0; i < count; i++) {
368+
data[i] = std::move(p_from[i]);
369+
}
370+
}
341371

342372
_FORCE_INLINE_ ~LocalVector() {
343373
if (data) {

0 commit comments

Comments
 (0)