mirror of
https://github.com/godotengine/godot.git
synced 2025-12-08 06:09:55 +00:00
Simplify Memory::memnew_arr_placement to always initialize memory, to force callers to make the decision of whether to initialize.
This commit is contained in:
parent
7a0ab9d561
commit
4371aa864d
5 changed files with 16 additions and 16 deletions
|
|
@ -208,7 +208,7 @@ public:
|
|||
return _ptr[p_index];
|
||||
}
|
||||
|
||||
template <bool p_ensure_zero = false>
|
||||
template <bool p_initialize = true>
|
||||
Error resize(Size p_size);
|
||||
|
||||
_FORCE_INLINE_ void remove_at(Size p_index) {
|
||||
|
|
@ -366,7 +366,7 @@ Error CowData<T>::_fork_allocate(USize p_size) {
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
template <bool p_ensure_zero>
|
||||
template <bool p_initialize>
|
||||
Error CowData<T>::resize(Size p_size) {
|
||||
ERR_FAIL_COND_V(p_size < 0, ERR_INVALID_PARAMETER);
|
||||
|
||||
|
|
@ -380,8 +380,12 @@ Error CowData<T>::resize(Size p_size) {
|
|||
return error;
|
||||
}
|
||||
|
||||
if (p_size > prev_size) {
|
||||
memnew_arr_placement<p_ensure_zero>(_ptr + prev_size, p_size - prev_size);
|
||||
if constexpr (p_initialize) {
|
||||
if (p_size > prev_size) {
|
||||
memnew_arr_placement(_ptr + prev_size, p_size - prev_size);
|
||||
}
|
||||
} else {
|
||||
static_assert(std::is_trivially_destructible_v<T>);
|
||||
}
|
||||
|
||||
return OK;
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ public:
|
|||
constexpr Error resize_initialized(uint32_t p_size) {
|
||||
if (p_size > _size) {
|
||||
ERR_FAIL_COND_V(p_size > CAPACITY, ERR_OUT_OF_MEMORY);
|
||||
memnew_arr_placement<true>(ptr() + _size, p_size - _size);
|
||||
memnew_arr_placement(ptr() + _size, p_size - _size);
|
||||
} else if (p_size < _size) {
|
||||
if constexpr (!std::is_trivially_destructible_v<T>) {
|
||||
for (uint32_t i = p_size; i < _size; i++) {
|
||||
|
|
|
|||
|
|
@ -93,13 +93,13 @@ public:
|
|||
_FORCE_INLINE_ operator Span<T>() const { return _cowdata.span(); }
|
||||
_FORCE_INLINE_ Span<T> span() const { return _cowdata.span(); }
|
||||
|
||||
_FORCE_INLINE_ void clear() { resize(0); }
|
||||
_FORCE_INLINE_ void clear() { _cowdata.clear(); }
|
||||
_FORCE_INLINE_ bool is_empty() const { return _cowdata.is_empty(); }
|
||||
|
||||
_FORCE_INLINE_ T get(Size p_index) { return _cowdata.get(p_index); }
|
||||
_FORCE_INLINE_ const T &get(Size p_index) const { return _cowdata.get(p_index); }
|
||||
_FORCE_INLINE_ void set(Size p_index, const T &p_elem) { _cowdata.set(p_index, p_elem); }
|
||||
Error resize(Size p_size) { return _cowdata.resize(p_size); }
|
||||
Error resize(Size p_size) { return _cowdata.template resize<!std::is_trivially_constructible_v<T>>(p_size); }
|
||||
Error resize_zeroed(Size p_size) { return _cowdata.template resize<true>(p_size); }
|
||||
_FORCE_INLINE_ const T &operator[](Size p_index) const { return _cowdata.get(p_index); }
|
||||
// Must take a copy instead of a reference (see GH-31736).
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue