From 9142592077bc1a575b0b1ee424a652f1fb12833e Mon Sep 17 00:00:00 2001 From: Relintai Date: Sun, 5 Feb 2023 09:50:03 +0100 Subject: [PATCH] Small improvements to MLPPVector. --- mlpp/lin_alg/mlpp_vector.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/mlpp/lin_alg/mlpp_vector.h b/mlpp/lin_alg/mlpp_vector.h index 68b2418..fcb7e79 100644 --- a/mlpp/lin_alg/mlpp_vector.h +++ b/mlpp/lin_alg/mlpp_vector.h @@ -41,6 +41,12 @@ public: --_size; + if (_size == 0) { + memfree(_data); + _data = NULL; + return; + } + for (int i = p_index; i < _size; i++) { _data[i] = _data[i + 1]; } @@ -55,6 +61,12 @@ public: ERR_FAIL_INDEX(p_index, _size); _size--; + if (_size == 0) { + memfree(_data); + _data = NULL; + return; + } + if (_size > p_index) { _data[p_index] = _data[_size]; } @@ -94,7 +106,6 @@ public: _FORCE_INLINE_ void clear() { resize(0); } _FORCE_INLINE_ void reset() { - clear(); if (_data) { memfree(_data); _data = NULL;