Merge pull request #106730 from Ivorforce/simplify-memnew-arr-placement

Simplify `Memory::memnew_arr_placement` to always initialize memory
This commit is contained in:
Thaddeus Crews 2025-05-26 11:24:43 -05:00
commit 8bcec7afa9
No known key found for this signature in database
GPG key ID: 8C6E5FEB5FC03CCC
5 changed files with 16 additions and 16 deletions

View file

@ -196,19 +196,15 @@ T *memnew_arr_template(size_t p_elements) {
}
// Fast alternative to a loop constructor pattern.
template <bool p_ensure_zero = false, typename T>
template <typename T>
_FORCE_INLINE_ void memnew_arr_placement(T *p_start, size_t p_num) {
if constexpr (std::is_trivially_constructible_v<T> && !p_ensure_zero) {
// Don't need to do anything :)
(void)p_start;
(void)p_num;
} else if constexpr (is_zero_constructible_v<T>) {
if constexpr (is_zero_constructible_v<T>) {
// Can optimize with memset.
memset(static_cast<void *>(p_start), 0, p_num * sizeof(T));
} else {
// Need to use a for loop.
for (size_t i = 0; i < p_num; i++) {
memnew_placement(p_start + i, T);
memnew_placement(p_start + i, T());
}
}
}