Changeset - r13299:70ff2a09b940
[Not reviewed]
master
0 1 0
rubidium - 15 years ago 2009-10-20 16:36:35
rubidium@openttd.org
(svn r17818) -Codechange: iterate the cargo list from the back when trying to merge packets. Chances are higher that the last packet (in the FIFO-ish queue) is mergeable with the to be added package. If a train gets loaded packets get split up and put into the different carriages, at unload they are unloaded in the same order so the last in the FIFO-ish queue is likely the packet it can merge with.
This results in a 5-10% performance improvement of CargoList's Append/MoveTo without performance degradation of AgeCargo.
1 file changed with 2 insertions and 3 deletions:
0 comments (0 inline, 0 general)
src/cargopacket.cpp
Show inline comments
 
@@ -109,14 +109,14 @@ template <class Tinst>
 
void CargoList<Tinst>::Append(CargoPacket *cp)
 
{
 
	assert(cp != NULL);
 
	static_cast<Tinst *>(this)->AddToCache(cp);
 

	
 
	for (Iterator it(this->packets.begin()); it != this->packets.end(); it++) {
 
	for (List::reverse_iterator it(this->packets.rbegin()); it != this->packets.rend(); it++) {
 
		CargoPacket *icp = *it;
 
		if (Tinst::AreMergable(icp, cp) && icp->count + cp->count <= CargoPacket::MAX_COUNT) {
 
			icp->count        += cp->count;
 
			icp->feeder_share += cp->feeder_share;
 

	
 
			static_cast<Tinst *>(this)->AddToCache(cp);
 
			delete cp;
 
			return;
 
		}
 
@@ -124,7 +124,6 @@ void CargoList<Tinst>::Append(CargoPacke
 

	
 
	/* The packet could not be merged with another one */
 
	this->packets.push_back(cp);
 
	static_cast<Tinst *>(this)->AddToCache(cp);
 
}
 

	
 

	
0 comments (0 inline, 0 general)