aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/array.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/common/array.h b/common/array.h
index 91f1083338..eb6b0cddb6 100644
--- a/common/array.h
+++ b/common/array.h
@@ -159,6 +159,22 @@ public:
}
}
+ void resize(uint newSize) {
+ if (newSize == _size)
+ return;
+
+ T *old_data = _data;
+ _capacity = newSize;
+ _data = new T[newSize];
+ if (old_data) {
+ // Copy old data
+ int cnt = (_size < newSize ? _size : newSize);
+ copy(old_data, old_data + cnt, _data);
+ delete [] old_data;
+ }
+ _size = newSize;
+ }
+
protected:
void ensureCapacity(uint len) {
if (len >= _capacity)