(svn r14669) -Codechange: use SmallVector instead of std::list at one place

This commit is contained in:
smatz 2008-12-13 15:59:25 +00:00
parent 0bf775a20a
commit 3cd2957544
2 changed files with 19 additions and 8 deletions

View File

@ -44,6 +44,17 @@ public:
this->items = 0; this->items = 0;
} }
/**
* 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. * Compact the list down to the smallest block size boundary.
*/ */

View File

@ -28,6 +28,7 @@
#include "rail.h" #include "rail.h"
#include "settings_type.h" #include "settings_type.h"
#include "aircraft.h" #include "aircraft.h"
#include "core/smallvec_type.hpp"
#include <map> #include <map>
@ -1086,15 +1087,14 @@ struct ListOrderChange {
EngineID target; EngineID target;
}; };
static std::list<ListOrderChange> _list_order_changes; static SmallVector<ListOrderChange, 16> _list_order_changes;
void AlterVehicleListOrder(EngineID engine, EngineID target) void AlterVehicleListOrder(EngineID engine, EngineID target)
{ {
/* Add the list order change to a queue */ /* Add the list order change to a queue */
ListOrderChange loc; ListOrderChange *loc = _list_order_changes.Append();
loc.engine = engine; loc->engine = engine;
loc.target = target; loc->target = target;
_list_order_changes.push_back(loc);
} }
void CommitVehicleListOrderChanges() void CommitVehicleListOrderChanges()
@ -1103,8 +1103,8 @@ void CommitVehicleListOrderChanges()
typedef std::map<uint16, Engine*> ListPositionMap; typedef std::map<uint16, Engine*> ListPositionMap;
ListPositionMap lptr_map; ListPositionMap lptr_map;
std::list<ListOrderChange>::iterator it; const ListOrderChange *end = _list_order_changes.End();
for (it = _list_order_changes.begin(); it != _list_order_changes.end(); ++it) { for (const ListOrderChange *it = _list_order_changes.Begin(); it != end; ++it) {
EngineID engine = it->engine; EngineID engine = it->engine;
EngineID target = it->target; EngineID target = it->target;
@ -1139,5 +1139,5 @@ void CommitVehicleListOrderChanges()
} }
/* Clear out the queue */ /* Clear out the queue */
_list_order_changes.clear(); _list_order_changes.Reset();
} }