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 24a8c05 commit e87f64f
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions core/templates/local_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,16 @@ class LocalVector {

operator Vector<T>() const {
Vector<T> ret;
ret.resize(size());
ret.resize(count);
T *w = ret.ptrw();
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 e87f64f

Please sign in to comment.