[Scummvm-cvs-logs] SF.net SVN: scummvm:[39921] scummvm/trunk

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Sat Apr 11 02:29:34 CEST 2009


Revision: 39921
          http://scummvm.svn.sourceforge.net/scummvm/?rev=39921&view=rev
Author:   fingolfin
Date:     2009-04-11 00:29:34 +0000 (Sat, 11 Apr 2009)

Log Message:
-----------
COMMON: Added unit test for Common::List::size(); made List::size() slightly more efficient; same for remove() and operator=

Modified Paths:
--------------
    scummvm/trunk/common/list.h
    scummvm/trunk/test/common/list.h

Modified: scummvm/trunk/common/list.h
===================================================================
--- scummvm/trunk/common/list.h	2009-04-11 00:29:12 UTC (rev 39920)
+++ scummvm/trunk/common/list.h	2009-04-11 00:29:34 UTC (rev 39921)
@@ -119,8 +119,9 @@
 
 	void remove(const t_T &val) {
 		iterator i = begin();
-		while (i != end())
-			if (val == i.operator*())
+		const iterator e = end();
+		while (i != e)
+			if (val == *i)
 				i = erase(i);
 			else
 				++i;
@@ -135,16 +136,18 @@
 	List<t_T> &operator=(const List<t_T> &list) {
 		if (this != &list) {
 			iterator i;
-			const_iterator j;
+			const iterator e = end();
+			const_iterator i2;
+			const_iterator e2 = list.end();
 
-			for (i = begin(), j = list.begin();  (i != end()) && (j != list.end()) ; ++i, ++j) {
-				static_cast<Node *>(i._node)->_data = static_cast<const Node *>(j._node)->_data;
+			for (i = begin(), i2 = list.begin();  (i != e) && (i2 != e2) ; ++i, ++i2) {
+				static_cast<Node *>(i._node)->_data = static_cast<const Node *>(i2._node)->_data;
 			}
 
-			if (i == end())
-				insert(i, j, list.end());
+			if (i == e)
+				insert(i, i2, e2);
 			else
-				erase(i, end());
+				erase(i, e);
 		}
 
 		return *this;
@@ -152,7 +155,7 @@
 
 	uint size() const {
 		int n = 0;
-		for (const_iterator i = begin(); i != end(); ++i)
+		for (const NodeBase *cur = _anchor._next; cur != &_anchor; cur = cur->_next)
 			++n;
 		return n;
 	}

Modified: scummvm/trunk/test/common/list.h
===================================================================
--- scummvm/trunk/test/common/list.h	2009-04-11 00:29:12 UTC (rev 39920)
+++ scummvm/trunk/test/common/list.h	2009-04-11 00:29:34 UTC (rev 39921)
@@ -16,6 +16,19 @@
 		TS_ASSERT( container.empty() );
 	}
 
+	public:
+	void test_size( void )
+	{
+		Common::List<int> container;
+		TS_ASSERT( container.size() == 0 );
+		container.push_back(17);
+		TS_ASSERT( container.size() == 1 );
+		container.push_back(33);
+		TS_ASSERT( container.size() == 2 );
+		container.clear();
+		TS_ASSERT( container.size() == 0 );
+	}
+
 	void test_iterator_begin_end( void )
 	{
 		Common::List<int> container;


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list