From 1ded9cff77d06d3cca6754f3b546fc3eaacaacd0 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Sun, 12 Dec 2004 21:54:33 +0000 Subject: Optimized List assignment operator, thanks to h00ligan svn-id: r16042 --- common/list.h | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'common') diff --git a/common/list.h b/common/list.h index 523fd5b94c..b37b8b1b64 100644 --- a/common/list.h +++ b/common/list.h @@ -171,10 +171,17 @@ public: List& operator =(const List& 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 *>(i._node)->_data = static_cast *>(j._node)->_data; + } + + if(i == end()) + insert(i, j, list.end()); + else + erase(i, end()); } return *this; -- cgit v1.2.3