aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorMax Horn2003-10-17 10:23:52 +0000
committerMax Horn2003-10-17 10:23:52 +0000
commit3e68577bae45636be5c758d8c381a832655d9247 (patch)
tree4ceab554261d74c82ba0ba7de0eee1fecf6097e0 /common
parentb86ae6641bea6d4d7a4e3f8e90cf976b5a63c7b1 (diff)
downloadscummvm-rg350-3e68577bae45636be5c758d8c381a832655d9247.tar.gz
scummvm-rg350-3e68577bae45636be5c758d8c381a832655d9247.tar.bz2
scummvm-rg350-3e68577bae45636be5c758d8c381a832655d9247.zip
added push_back method with List arg (append one list to another one efficiently)
svn-id: r10850
Diffstat (limited to 'common')
-rw-r--r--common/list.h10
1 files changed, 9 insertions, 1 deletions
diff --git a/common/list.h b/common/list.h
index 7d7ccb0283..8c3d31d808 100644
--- a/common/list.h
+++ b/common/list.h
@@ -57,12 +57,20 @@ public:
_data[_size++] = element;
}
+ void push_back(const List<T>& list) {
+ ensureCapacity(_size + list._size);
+ for (int i = 0; i < list._size; i++)
+ _data[_size++] = list._data[i];
+ }
+
void insert_at(int idx, const T& element) {
assert(idx >= 0 && idx <= _size);
ensureCapacity(_size + 1);
// The following loop is not efficient if you can just memcpy things around.
// e.g. if you have a list of ints. But for real objects (String...), memcpy
- // is *not* usually a good idea!
+ // usually isn't correct (specifically, for any class which has a non-default
+ // copy behaviour. E.g. the String class uses a refCounter which has to be
+ // updated whenever a String is copied.
for (int i = _size; i > idx; i--) {
_data[i] = _data[i-1];
}