[Scummvm-cvs-logs] CVS: scummvm/common list.h,1.18,1.19
Max Horn
fingolfin at users.sourceforge.net
Sun Dec 12 13:55:01 CET 2004
Update of /cvsroot/scummvm/scummvm/common
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24204
Modified Files:
list.h
Log Message:
Optimized List assignment operator, thanks to h00ligan
Index: list.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/common/list.h,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- list.h 12 Dec 2004 21:38:11 -0000 1.18
+++ list.h 12 Dec 2004 21:54:33 -0000 1.19
@@ -171,10 +171,17 @@
List<T>& operator =(const List<T>& list) {
if (this != &list) {
- // TODO: This could (and should) be optimized, by reusing
- // the existing nodes...
- clear();
- insert(begin(), list.begin(), list.end());
+ iterator i;
+ const_iterator j;
+
+ for (i = begin(), j = list.begin(); (i != end()) && (j != list.end()) ; ++i, ++j) {
+ static_cast<Node<T> *>(i._node)->_data = static_cast<Node<T> *>(j._node)->_data;
+ }
+
+ if(i == end())
+ insert(i, j, list.end());
+ else
+ erase(i, end());
}
return *this;
More information about the Scummvm-git-logs
mailing list