aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorMax Horn2004-12-12 21:54:33 +0000
committerMax Horn2004-12-12 21:54:33 +0000
commit1ded9cff77d06d3cca6754f3b546fc3eaacaacd0 (patch)
tree4026e88ec4fe62f7da061c698d4b5ec927a67c4e /common
parent9e4a529ef9b2e2760c79fd729ad67545302f7c63 (diff)
downloadscummvm-rg350-1ded9cff77d06d3cca6754f3b546fc3eaacaacd0.tar.gz
scummvm-rg350-1ded9cff77d06d3cca6754f3b546fc3eaacaacd0.tar.bz2
scummvm-rg350-1ded9cff77d06d3cca6754f3b546fc3eaacaacd0.zip
Optimized List assignment operator, thanks to h00ligan
svn-id: r16042
Diffstat (limited to 'common')
-rw-r--r--common/list.h15
1 files changed, 11 insertions, 4 deletions
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<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;