diff options
| author | Jonathan Bradley <jcb@pikum.xyz> | 2023-11-29 21:00:12 -0500 |
|---|---|---|
| committer | Jonathan Bradley <jcb@pikum.xyz> | 2023-11-29 21:00:12 -0500 |
| commit | 8142cbb3d1a926d5c8cb5c59a0ea259948c59ad1 (patch) | |
| tree | 02691ec4070e4a0841d641f6f63c10c3e436cbdc /src/dynamic-array.hpp | |
| parent | 67e40a5d4d3b4e7ed6823e9a768cea48cfd6cfe6 (diff) | |
DynArray<T>::Reserve should only run destructor on elements that actually exist
Diffstat (limited to 'src/dynamic-array.hpp')
| -rw-r--r-- | src/dynamic-array.hpp | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/dynamic-array.hpp b/src/dynamic-array.hpp index 6813edf..876f71d 100644 --- a/src/dynamic-array.hpp +++ b/src/dynamic-array.hpp @@ -195,8 +195,10 @@ template <typename T> inline void DynArray<T>::Reserve(int64_t count) { template <typename T> inline void DynArray<T>::Resize(int64_t count) { int64_t beforeCount = this->elementCount; if IS_DESTRUCTIBLE(T) { - for (long i = count; i > beforeCount; --i) { - reinterpret_cast<T *>(this->ptr + (i * sizeof(T)))->~T(); + if (beforeCount > count) { + for (long i = count; i > beforeCount; --i) { + reinterpret_cast<T *>(this->ptr + (i * sizeof(T)))->~T(); + } } } if (count > 0) { |
