[Scummvm-cvs-logs] CVS: scummvm/common list.h,1.9,1.10
Max Horn
fingolfin at users.sourceforge.net
Fri Oct 17 03:26:20 CEST 2003
Update of /cvsroot/scummvm/scummvm/common
In directory sc8-pr-cvs1:/tmp/cvs-serv30070
Modified Files:
list.h
Log Message:
added push_back method with List arg (append one list to another one efficiently)
Index: list.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/common/list.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- list.h 5 Oct 2003 14:02:28 -0000 1.9
+++ list.h 17 Oct 2003 10:23:52 -0000 1.10
@@ -57,12 +57,20 @@
_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];
}
More information about the Scummvm-git-logs
mailing list