Skip to content

Commit

Permalink
Make LocalVector -> Vector automatic conversion safe for non-triv…
Browse files Browse the repository at this point in the history
…ial types.
  • Loading branch information
Ivorforce committed Dec 21, 2024
1 parent 89001f9 commit 0e32f3b
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions core/templates/local_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,16 @@ class LocalVector {

operator Vector<T>() const {
Vector<T> ret;
ret.resize(size());
ret.resize(count);
T *w = ret.ptrw();
if (w) {
memcpy(w, data, sizeof(T) * count);
if constexpr (std::is_trivially_copyable_v<T>) {
memcpy(w, data, sizeof(T) * count);
} else {
for (U i = 0; i < count; i++) {
w[i] = data[i];
}
}
}
return ret;
}
Expand Down

0 comments on commit 0e32f3b

Please sign in to comment.