diff options
author | rubidium <rubidium@openttd.org> | 2007-08-03 18:34:47 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2007-08-03 18:34:47 +0000 |
commit | 7e9594e0a506f00951db4c3c654bb819b89d0d66 (patch) | |
tree | 3a34c157c90efc45430d20db9eeb680237fed8dc | |
parent | c9c2cd8d2e67608eb13de9c7a058960d1687c833 (diff) | |
download | openttd-7e9594e0a506f00951db4c3c654bb819b89d0d66.tar.xz |
(svn r10768) -Codechange: allow to specify from which index to search for a free pool item.
-rw-r--r-- | src/oldpool.h | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/src/oldpool.h b/src/oldpool.h index 4c1b757bf..eebd31ede 100644 --- a/src/oldpool.h +++ b/src/oldpool.h @@ -254,16 +254,28 @@ struct PoolItem { return false; } -private: +protected: /** * Allocate a pool item; possibly allocate a new block in the pool. * @return the allocated pool item (or NULL when the pool is full). */ static T *AllocateRaw() { - for (T *t = Tpool->Get(Tpool->first_free_index); t != NULL; t = (t->index + 1U < Tpool->GetSize()) ? Tpool->Get(t->index + 1U) : NULL) { + return AllocateRaw(Tpool->first_free_index); + } + + /** + * Allocate a pool item; possibly allocate a new block in the pool. + * @param first the first pool item to start searching + * @return the allocated pool item (or NULL when the pool is full). + */ + static T *AllocateRaw(uint &first) + { + uint last_minus_one = Tpool->GetSize(); + + for (T *t = Tpool->Get(first); t != NULL; t = (t->index < last_minus_one) ? Tpool->Get(t->index + 1U) : NULL) { if (!t->IsValid()) { - Tpool->first_free_index = t->index; + first = t->index; Tid index = t->index; memset(t, 0, Tpool->item_size); @@ -273,7 +285,7 @@ private: } /* Check if we can add a block to the pool */ - if (Tpool->AddBlockToPool()) return AllocateRaw(); + if (Tpool->AddBlockToPool()) return AllocateRaw(first); return NULL; } |