summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/dynamic-array.hpp23
1 files changed, 15 insertions, 8 deletions
diff --git a/src/dynamic-array.hpp b/src/dynamic-array.hpp
index fa1e665..e5567f4 100644
--- a/src/dynamic-array.hpp
+++ b/src/dynamic-array.hpp
@@ -35,7 +35,7 @@ struct DynArray: DynArrayBase {
T& Push();
void Push(const T &val);
T Pop();
- void Remove(std::size_t index);
+ void Remove(std::size_t index, int64_t count = 1);
void Reserve(int64_t count);
void Resize(int64_t count);
protected:
@@ -165,18 +165,25 @@ template <typename T> inline T DynArray<T>::Pop() {
return *reinterpret_cast<T *>((this->ptr + (sizeof(T) * this->elementCount)));
}
-template <typename T> inline void DynArray<T>::Remove(std::size_t index) {
- assert(this->elementCount == 0 && "Invalid DynArray<T>::Remove() - Contains no elements");
+template <typename T> inline void DynArray<T>::Remove(std::size_t index, int64_t count) {
assert(index >= this->elementCount && "Invalid DynArray<T>::Remove() - Out of bounds");
- uint64_t moveCount = (this->elementCount - index - 1);
- T *tmp = Pke_New<T>(moveCount, this->bkt);
+ int64_t moveCount = (this->elementCount - index - count);
+ assert(moveCount >= 0 && "Invalid DynArray<T>::Remove() - Removing too many elements");
+ assert(moveCount <= this->elementCount - index && "Invalid DynArray<T>::Remove() - Removing too many elements");
if IS_DESTRUCTIBLE(T) {
- reinterpret_cast<T>(this->ptr + (index * sizeof(T))).~T();
+ for (long i = 0; i < count; ++i) {
+ reinterpret_cast<T *>(this->ptr + ((index + i) * sizeof(T)))->~T();
+ }
}
- memcpy(tmp, this->ptr + (sizeof(T) * (index + 1)), sizeof(T) * moveCount);
+ if (moveCount == 0) {
+ this->elementCount = index;
+ return;
+ }
+ T *tmp = Pke_New<T>(moveCount, this->bkt);
+ memcpy(tmp, this->ptr + (sizeof(T) * (index + count)), sizeof(T) * moveCount);
memcpy(this->ptr + (sizeof(T) * index), tmp, sizeof(T) * moveCount);
Pke_Delete<T>(tmp, moveCount, this->bkt);
- this->elementCount -= 1;
+ this->elementCount -= count;
}
template <typename T> inline void DynArray<T>::Reserve(int64_t count) {