summaryrefslogtreecommitdiff
path: root/src/oldpool.h
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2007-08-02 10:47:00 +0000
committerrubidium <rubidium@openttd.org>2007-08-02 10:47:00 +0000
commit9009f0aa2042c1563efc565423962da737f40011 (patch)
tree4a970c32e71bb3ecac18b4235a97e577a28e036e /src/oldpool.h
parent9378e5fd3845935b0ec00be40a2de8a0748ab7d0 (diff)
downloadopenttd-9009f0aa2042c1563efc565423962da737f40011.tar.xz
(svn r10747) -Codechange: add a variable that points to some index in the pool that is not beyond the first free pool item. It does not necessarily point to the first free item, but it reduces allocation time as it does not have to start at the first item in the pool to find the first free item.
Diffstat (limited to 'src/oldpool.h')
-rw-r--r--src/oldpool.h5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/oldpool.h b/src/oldpool.h
index 5e5b53c59..6802cb63e 100644
--- a/src/oldpool.h
+++ b/src/oldpool.h
@@ -42,6 +42,7 @@ protected:
uint total_items; ///< How many items we now have in this pool
public:
+ uint first_free_index; ///< The index of the first free pool item in this pool
byte **blocks; ///< An array of blocks (one block hold all the items)
/**
@@ -170,6 +171,7 @@ struct PoolItem {
*/
virtual ~PoolItem()
{
+ if (this->index < Tpool->first_free_index) Tpool->first_free_index = this->index;
}
/**
@@ -259,8 +261,9 @@ private:
*/
static T *AllocateRaw()
{
- for (T *t = Tpool->Get(0); t != NULL; t = (t->index + 1U < Tpool->GetSize()) ? Tpool->Get(t->index + 1U) : NULL) {
+ for (T *t = Tpool->Get(Tpool->first_free_index); t != NULL; t = (t->index + 1U < Tpool->GetSize()) ? Tpool->Get(t->index + 1U) : NULL) {
if (!t->IsValid()) {
+ Tpool->first_free_index = t->index;
Tid index = t->index;
memset(t, 0, sizeof(T));