summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/dynamic-array.hpp11
-rw-r--r--src/event.cpp2
2 files changed, 12 insertions, 1 deletions
diff --git a/src/dynamic-array.hpp b/src/dynamic-array.hpp
index 343f6c1..645f9c8 100644
--- a/src/dynamic-array.hpp
+++ b/src/dynamic-array.hpp
@@ -31,6 +31,7 @@ struct DynArray: DynArrayBase {
T *GetPtr();
const int64_t Count();
bool Has(const T &val);
+ void Push();
void Push(const T &val);
T Pop();
void Remove(std::size_t index);
@@ -126,6 +127,16 @@ template <typename T> inline bool DynArray<T>::Has(const T &val) {
return false;
}
+template <typename T> inline void DynArray<T>::Push() {
+ if (this->elementCount + 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);
+ const auto &targetItem = new(itemPtr) T{};
+ this->elementCount += 1;
+}
+
template <typename T> inline void DynArray<T>::Push(const T &val) {
if (this->elementCount + 1 > this->reservedCount) {
auto safeReserveCount = this->reservedCount < 2 ? 2 : this->reservedCount;
diff --git a/src/event.cpp b/src/event.cpp
index 62ebd88..7d33626 100644
--- a/src/event.cpp
+++ b/src/event.cpp
@@ -26,7 +26,7 @@ void Event_RegisterCallback(const char *name, EventHandler handler) {
EventBucket *bkt = nullptr;
EventBucketFind(name, safeName, bkt);
if (bkt == nullptr) {
- eventBuckets.Push(EventBucket{});
+ eventBuckets.Push();
bkt = eventBuckets.GetPtr() + (sizeof(EventBucket) * (eventBuckets.Count() - 1));
memcpy(bkt->name, safeName, 16);
}