[Scummvm-cvs-logs] SF.net SVN: scummvm:[40262] scummvm/trunk/common/array.h

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Sun May 3 11:00:53 CEST 2009


Revision: 40262
          http://scummvm.svn.sourceforge.net/scummvm/?rev=40262&view=rev
Author:   fingolfin
Date:     2009-05-03 09:00:53 +0000 (Sun, 03 May 2009)

Log Message:
-----------
COMMON: Changed Array::resize to not shrink the internal storage if we shrink the array

Modified Paths:
--------------
    scummvm/trunk/common/array.h

Modified: scummvm/trunk/common/array.h
===================================================================
--- scummvm/trunk/common/array.h	2009-05-03 09:00:13 UTC (rev 40261)
+++ scummvm/trunk/common/array.h	2009-05-03 09:00:53 UTC (rev 40262)
@@ -30,6 +30,12 @@
 
 namespace Common {
 
+// TODO: Improve the storage management of this class.
+// In particular, don't use new[] and delete[], but rather
+// construct/destruct objects manually. This way, we can
+// ensure that storage which is not currently used does not
+// correspond to a live active object.
+// (This is only of interest for array of non-POD objects).
 template<class T>
 class Array {
 protected:
@@ -196,18 +202,7 @@
 	}
 
 	void resize(uint newSize) {
-		if (newSize == _size)
-			return;
-
-		T *old_storage = _storage;
-		_capacity = newSize;
-		_storage = new T[newSize];
-		if (old_storage) {
-			// Copy old data
-			int cnt = (_size < newSize ? _size : newSize);
-			copy(old_storage, old_storage + cnt, _storage);
-			delete[] old_storage;
-		}
+		reserve(newSize);
 		_size = newSize;
 	}
 


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