Skip to content

Commit 0e32f3b

Browse files
committed
Make LocalVector -> Vector automatic conversion safe for non-trivial types.
1 parent 89001f9 commit 0e32f3b

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

core/templates/local_vector.h

+8-2
Original file line numberDiff line numberDiff line change
@@ -295,10 +295,16 @@ class LocalVector {
295295

296296
operator Vector<T>() const {
297297
Vector<T> ret;
298-
ret.resize(size());
298+
ret.resize(count);
299299
T *w = ret.ptrw();
300300
if (w) {
301-
memcpy(w, data, sizeof(T) * count);
301+
if constexpr (std::is_trivially_copyable_v<T>) {
302+
memcpy(w, data, sizeof(T) * count);
303+
} else {
304+
for (U i = 0; i < count; i++) {
305+
w[i] = data[i];
306+
}
307+
}
302308
}
303309
return ret;
304310
}

0 commit comments

Comments
 (0)