Merge pull request #100683 from Ivorforce/localvector-vector-conversion-typesafe-copy

Make `LocalVector` -> `Vector` automatic conversion safe for non-trivial types.
This commit is contained in:
Rémi Verschelde 2024-12-22 00:10:19 +01:00
commit 31c07776f4
No known key found for this signature in database
GPG key ID: C3336907360768E1

View file

@ -295,10 +295,16 @@ public:
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;
}