From 3e68577bae45636be5c758d8c381a832655d9247 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Fri, 17 Oct 2003 10:23:52 +0000 Subject: added push_back method with List arg (append one list to another one efficiently) svn-id: r10850 --- common/list.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'common') 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& 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]; } -- cgit v1.2.3