Skip to content

Commit

Permalink
Merge pull request godotengine#100683 from Ivorforce/localvector-vect…
Browse files Browse the repository at this point in the history
…or-conversion-typesafe-copy

Make `LocalVector` -> `Vector` automatic conversion safe for non-trivial types.
  • Loading branch information
akien-mga committed Dec 21, 2024
2 parents 9f42d1c + 0e32f3b commit 31c0777
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 31c0777

Please sign in to comment.