diff options
author | Max Horn | 2009-05-03 09:00:53 +0000 |
---|---|---|
committer | Max Horn | 2009-05-03 09:00:53 +0000 |
commit | 4d57c1f9a9e849f5d8cd3d56da6bcb51da0789d5 (patch) | |
tree | ff7b91a24fd93141d21f6a05068fd7e0967d3bb3 | |
parent | c379927d3a6c0a568e618d7f8113f340f7afe6d5 (diff) | |
download | scummvm-rg350-4d57c1f9a9e849f5d8cd3d56da6bcb51da0789d5.tar.gz scummvm-rg350-4d57c1f9a9e849f5d8cd3d56da6bcb51da0789d5.tar.bz2 scummvm-rg350-4d57c1f9a9e849f5d8cd3d56da6bcb51da0789d5.zip |
COMMON: Changed Array::resize to not shrink the internal storage if we shrink the array
svn-id: r40262
-rw-r--r-- | common/array.h | 19 |
1 files changed, 7 insertions, 12 deletions
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 T> 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; } |