aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Horn2011-05-16 13:58:59 +0200
committerMax Horn2011-05-16 13:58:59 +0200
commiteedb2d721fa2577a02695f95135f856b97e224c8 (patch)
treee33950707c8ecc390ab57109e9e81e5ed3d0a17b
parent85d5eec95056f438bca709a0d3998885fb81e774 (diff)
downloadscummvm-rg350-eedb2d721fa2577a02695f95135f856b97e224c8.tar.gz
scummvm-rg350-eedb2d721fa2577a02695f95135f856b97e224c8.tar.bz2
scummvm-rg350-eedb2d721fa2577a02695f95135f856b97e224c8.zip
COMMON: Change Array::insert_aux to immediately assign newly allocated memory to _storage
-rw-r--r--common/array.h25
1 files changed, 12 insertions, 13 deletions
diff --git a/common/array.h b/common/array.h
index 6f8e7da579..a1db9a6494 100644
--- a/common/array.h
+++ b/common/array.h
@@ -238,15 +238,15 @@ public:
if (newCapacity <= _capacity)
return;
- T *old_storage = _storage;
+ T *oldStorage = _storage;
_capacity = newCapacity;
_storage = new T[newCapacity];
assert(_storage);
- if (old_storage) {
+ if (oldStorage) {
// Copy old data
- copy(old_storage, old_storage + _size, _storage);
- delete[] old_storage;
+ copy(oldStorage, oldStorage + _size, _storage);
+ delete[] oldStorage;
}
}
@@ -286,29 +286,28 @@ protected:
const uint n = last - first;
if (n) {
const uint idx = pos - _storage;
- T *newStorage = _storage;
+ T *oldStorage = _storage;
if (_size + n > _capacity) {
// If there is not enough space, allocate more and
// copy old elements over.
uint newCapacity = roundUpCapacity(_size + n);
- newStorage = new T[newCapacity];
- assert(newStorage);
- copy(_storage, _storage + idx, newStorage);
- pos = newStorage + idx;
+ _storage = new T[newCapacity];
+ assert(_storage);
+ copy(oldStorage, oldStorage + idx, _storage);
+ pos = _storage + idx;
}
// Make room for the new elements by shifting back
// existing ones.
- copy_backward(_storage + idx, _storage + _size, newStorage + _size + n);
+ copy_backward(oldStorage + idx, oldStorage + _size, _storage + _size + n);
// Insert the new elements.
copy(first, last, pos);
// Finally, update the internal state
- if (newStorage != _storage) {
- delete[] _storage;
+ if (_storage != oldStorage) {
+ delete[] oldStorage;
_capacity = roundUpCapacity(_size + n);
- _storage = newStorage;
}
_size += n;
}