(svn r14669) -Codechange: use SmallVector instead of std::list at one place
authorsmatz
Sat, 13 Dec 2008 15:59:25 +0000
changeset 10416 b35c0a4c73c5
parent 10415 fabf65e49e38
child 10417 a1a609566853
(svn r14669) -Codechange: use SmallVector instead of std::list at one place
src/core/smallvec_type.hpp
src/newgrf_engine.cpp
--- a/src/core/smallvec_type.hpp	Fri Dec 12 19:54:54 2008 +0000
+++ b/src/core/smallvec_type.hpp	Sat Dec 13 15:59:25 2008 +0000
@@ -45,6 +45,17 @@
 	}
 
 	/**
+	 * Remove all items from the list and free allocated memory.
+	 */
+	void Reset()
+	{
+		this->items = 0;
+		this->capacity = 0;
+		free(data);
+		data = NULL;
+	}
+
+	/**
 	 * Compact the list down to the smallest block size boundary.
 	 */
 	FORCEINLINE void Compact()
--- a/src/newgrf_engine.cpp	Fri Dec 12 19:54:54 2008 +0000
+++ b/src/newgrf_engine.cpp	Sat Dec 13 15:59:25 2008 +0000
@@ -28,6 +28,7 @@
 #include "rail.h"
 #include "settings_type.h"
 #include "aircraft.h"
+#include "core/smallvec_type.hpp"
 #include <map>
 
 
@@ -1086,15 +1087,14 @@
 	EngineID target;
 };
 
-static std::list<ListOrderChange> _list_order_changes;
+static SmallVector<ListOrderChange, 16> _list_order_changes;
 
 void AlterVehicleListOrder(EngineID engine, EngineID target)
 {
 	/* Add the list order change to a queue */
-	ListOrderChange loc;
-	loc.engine = engine;
-	loc.target = target;
-	_list_order_changes.push_back(loc);
+	ListOrderChange *loc = _list_order_changes.Append();
+	loc->engine = engine;
+	loc->target = target;
 }
 
 void CommitVehicleListOrderChanges()
@@ -1103,8 +1103,8 @@
 	typedef std::map<uint16, Engine*> ListPositionMap;
 	ListPositionMap lptr_map;
 
-	std::list<ListOrderChange>::iterator it;
-	for (it = _list_order_changes.begin(); it != _list_order_changes.end(); ++it) {
+	const ListOrderChange *end = _list_order_changes.End();
+	for (const ListOrderChange *it = _list_order_changes.Begin(); it != end; ++it) {
 		EngineID engine = it->engine;
 		EngineID target = it->target;
 
@@ -1139,5 +1139,5 @@
 	}
 
 	/* Clear out the queue */
-	_list_order_changes.clear();
+	_list_order_changes.Reset();
 }