From 4d57c1f9a9e849f5d8cd3d56da6bcb51da0789d5 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Sun, 3 May 2009 09:00:53 +0000 Subject: COMMON: Changed Array::resize to not shrink the internal storage if we shrink the array svn-id: r40262 --- common/array.h | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) (limited to 'common') diff --git a/common/array.h b/common/array.h index 1ce8df55a7..7ac08efa92 100644 --- a/common/array.h +++ b/common/array.h @@ -30,6 +30,12 @@ namespace Common { +// TODO: Improve the storage management of this class. +// In particular, don't use new[] and delete[], but rather +// construct/destruct objects manually. This way, we can +// ensure that storage which is not currently used does not +// correspond to a live active object. +// (This is only of interest for array of non-POD objects). template class Array { protected: @@ -196,18 +202,7 @@ public: } void resize(uint newSize) { - if (newSize == _size) - return; - - T *old_storage = _storage; - _capacity = newSize; - _storage = new T[newSize]; - if (old_storage) { - // Copy old data - int cnt = (_size < newSize ? _size : newSize); - copy(old_storage, old_storage + cnt, _storage); - delete[] old_storage; - } + reserve(newSize); _size = newSize; } -- cgit v1.2.3