summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/dynamic-array.hpp5
-rw-r--r--src/event.cpp3
2 files changed, 4 insertions, 4 deletions
diff --git a/src/dynamic-array.hpp b/src/dynamic-array.hpp
index 645f9c8..95ba967 100644
--- a/src/dynamic-array.hpp
+++ b/src/dynamic-array.hpp
@@ -31,7 +31,7 @@ struct DynArray: DynArrayBase {
T *GetPtr();
const int64_t Count();
bool Has(const T &val);
- void Push();
+ T& Push();
void Push(const T &val);
T Pop();
void Remove(std::size_t index);
@@ -127,7 +127,7 @@ template <typename T> inline bool DynArray<T>::Has(const T &val) {
return false;
}
-template <typename T> inline void DynArray<T>::Push() {
+template <typename T> inline T &DynArray<T>::Push() {
if (this->elementCount + 1 > this->reservedCount) {
auto safeReserveCount = this->reservedCount < 2 ? 2 : this->reservedCount;
DynArrayReserve(this, int64_t(safeReserveCount * 1.5));
@@ -135,6 +135,7 @@ template <typename T> inline void DynArray<T>::Push() {
auto itemPtr = this->ptr + (sizeof(T) * this->elementCount);
const auto &targetItem = new(itemPtr) T{};
this->elementCount += 1;
+ return *reinterpret_cast<T *>(itemPtr);
}
template <typename T> inline void DynArray<T>::Push(const T &val) {
diff --git a/src/event.cpp b/src/event.cpp
index b6e18b3..0b1d48d 100644
--- a/src/event.cpp
+++ b/src/event.cpp
@@ -26,8 +26,7 @@ void Event_RegisterCallback(const char *name, EventHandler handler) {
EventBucket *bkt = nullptr;
EventBucketFind(name, safeName, bkt);
if (bkt == nullptr) {
- eventBuckets.Push();
- bkt = eventBuckets.GetPtr() + (sizeof(EventBucket) * (eventBuckets.Count() - 1));
+ bkt = &eventBuckets.Push();
memcpy(bkt->name, safeName, 16);
}
bkt->callbacks.Push(handler);