diff options
author | Max Horn | 2008-02-27 14:06:06 +0000 |
---|---|---|
committer | Max Horn | 2008-02-27 14:06:06 +0000 |
commit | 142a39da22d8a8286ab929d9ad5a07839d7530c2 (patch) | |
tree | c1ac0d3de96f4b1a7757686113511a7efa3c2f6e /common | |
parent | 0a918b02fb126dad03eed0d9c1e2f0bc43b6aa56 (diff) | |
download | scummvm-rg350-142a39da22d8a8286ab929d9ad5a07839d7530c2.tar.gz scummvm-rg350-142a39da22d8a8286ab929d9ad5a07839d7530c2.tar.bz2 scummvm-rg350-142a39da22d8a8286ab929d9ad5a07839d7530c2.zip |
Added Array::resize() method
svn-id: r30983
Diffstat (limited to 'common')
-rw-r--r-- | common/array.h | 16 |
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) |