diff options
| author | Jonathan Bradley <jcb@pikum.xyz> | 2023-09-26 15:59:21 -0400 |
|---|---|---|
| committer | Jonathan Bradley <jcb@pikum.xyz> | 2023-09-26 15:59:21 -0400 |
| commit | 35759fe54afef2015685e004dfe76ff79c27e32e (patch) | |
| tree | 92ba44b98cdf6ea1b813af80dbb434e89c9a6f09 /src/dynamic-array.hpp | |
| parent | 9f4088ca25e34bc6fa8429add6237e67dba7da0b (diff) | |
minimum reserve size is two and invalid assert
Diffstat (limited to 'src/dynamic-array.hpp')
| -rw-r--r-- | src/dynamic-array.hpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/dynamic-array.hpp b/src/dynamic-array.hpp index f06ddac..6b22f6b 100644 --- a/src/dynamic-array.hpp +++ b/src/dynamic-array.hpp @@ -116,7 +116,7 @@ template <typename T> inline bool DynArray<T>::Has(const T &val) { template <typename T> inline void DynArray<T>::Push(const T &val) { if (this->elementCount + 1 > this->reservedCount) { - auto safeReserveCount = this->reservedCount == 0 ? 1 : this->reservedCount; + auto safeReserveCount = this->reservedCount < 2 ? 2 : this->reservedCount; DynArrayReserve(this, int64_t(safeReserveCount * 1.5)); } auto itemPtr = this->ptr + (sizeof(T) * this->elementCount); @@ -126,7 +126,7 @@ template <typename T> inline void DynArray<T>::Push(const T &val) { } template <typename T> inline T DynArray<T>::Pop() { - assert(this->elementCount == 0 && "Invalid DynArray<T>::Pop() - Contains no elements"); + assert(this->elementCount > 0 && "Invalid DynArray<T>::Pop() - Contains no elements"); this->elementCount -= 1; return *reinterpret_cast<T *>((this->ptr + (sizeof(T) * this->elementCount))); } |
