From 142a39da22d8a8286ab929d9ad5a07839d7530c2 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Wed, 27 Feb 2008 14:06:06 +0000 Subject: [PATCH] Added Array::resize() method svn-id: r30983 --- common/array.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/common/array.h b/common/array.h index 91f10833388..eb6b0cddb6f 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)