diff options
author | rtk0c <[email protected]> | 2023-06-15 18:14:02 -0700 |
---|---|---|
committer | rtk0c <[email protected]> | 2023-06-15 18:14:02 -0700 |
commit | 1717c62f258c3cad297e9d066da7cbe57f8be200 (patch) | |
tree | 5864784122bb413a79b088da0e093ec419903007 /source/10-common | |
parent | 434a274cc8b85cfb37309c0ac1b1470ed930d30f (diff) |
Changeset: 98 Cleanup and prepare for rewriting shader system
Diffstat (limited to 'source/10-common')
-rw-r--r-- | source/10-common/RapidJsonHelper.hpp | 4 | ||||
-rw-r--r-- | source/10-common/RingBuffer.hpp | 10 |
2 files changed, 11 insertions, 3 deletions
diff --git a/source/10-common/RapidJsonHelper.hpp b/source/10-common/RapidJsonHelper.hpp index 008c6bb..a992dbc 100644 --- a/source/10-common/RapidJsonHelper.hpp +++ b/source/10-common/RapidJsonHelper.hpp @@ -108,3 +108,7 @@ bool ReadVectorPrimitives(const rapidjson::Value& value, TContainer& list) { } } // namespace rapidjson + +inline rapidjson::GenericStringRef<char> operator""_rj_sv(const char* str, size_t len) { + return rapidjson::StringRef(str, len); +} diff --git a/source/10-common/RingBuffer.hpp b/source/10-common/RingBuffer.hpp index de8227c..4eaa007 100644 --- a/source/10-common/RingBuffer.hpp +++ b/source/10-common/RingBuffer.hpp @@ -72,7 +72,7 @@ public: RingBuffer() noexcept = default; ~RingBuffer() noexcept { - delete mRing; + delete[] mRing; } RingBuffer(const RingBuffer&) noexcept = delete; @@ -128,6 +128,7 @@ public: [[nodiscard]] T& operator[](size_type i) { return const_cast<T&>(const_cast<const RingBuffer&>(*this)[i]); } [[nodiscard]] const T& operator[](size_type i) const { + assert(mRing != nullptr); size_type idx = mHeadIdx + i; if (idx >= mCapacity) { idx -= mCapacity; @@ -136,6 +137,7 @@ public: } void push_back(T t) { + assert(mRing != nullptr); if (mTailIdx == mCapacity) { // Ring buffer is filled to the right, warp around to the beginning // mHeadIdx > 0 must be true, since we checked that as condition (1) above @@ -177,8 +179,10 @@ public: auto oldRing = mRing; auto newRing = mRing = new T[newCapacity]; - std::rotate_copy(oldRing, oldRing + mHeadIdx, oldRing + mCapacity, newRing); - delete oldRing; + if (oldRing != nullptr) { + std::rotate_copy(oldRing, oldRing + mHeadIdx, oldRing + mCapacity, newRing); + delete[] oldRing; + } mCapacity = newCapacity; mHeadIdx = 0; |