summaryrefslogtreecommitdiff
path: root/src/oldpool_func.h
diff options
context:
space:
mode:
authorsmatz <smatz@openttd.org>2008-04-06 23:49:45 +0000
committersmatz <smatz@openttd.org>2008-04-06 23:49:45 +0000
commit6af1fb2bdd32898d9456174d99413adf3e466797 (patch)
tree86bec7de682cc52c0fc3a81cb21a661c2b0d4a75 /src/oldpool_func.h
parent1bd5a29df5db4d1b6d3925f7f291bfae7688a6cd (diff)
downloadopenttd-6af1fb2bdd32898d9456174d99413adf3e466797.tar.xz
(svn r12599) -Codechange: force AllocateSafeRaw() to be linked to simplify compiler's decisions about inlining
Diffstat (limited to 'src/oldpool_func.h')
-rw-r--r--src/oldpool_func.h34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/oldpool_func.h b/src/oldpool_func.h
new file mode 100644
index 000000000..e4d1c47d5
--- /dev/null
+++ b/src/oldpool_func.h
@@ -0,0 +1,34 @@
+/* $Id$ */
+
+#ifndef OLDPOOL_FUNC_H
+
+#include "oldpool.h"
+
+/**
+ * Allocate a pool item; possibly allocate a new block in the pool.
+ * @param first the first pool item to start searching
+ * @pre first <= Tpool->GetSize()
+ * @return the allocated pool item (or NULL when the pool is full).
+ */
+template<typename T, typename Tid, OldMemoryPool<T> *Tpool> T *PoolItem<T, Tid, Tpool>::AllocateSafeRaw(uint &first)
+{
+ uint last_minus_one = Tpool->GetSize() - 1;
+
+ for (T *t = Tpool->Get(first); t != NULL; t = (t->index < last_minus_one) ? Tpool->Get(t->index + 1U) : NULL) {
+ if (!t->IsValid()) {
+ first = t->index;
+ Tid index = t->index;
+
+ memset(t, 0, Tpool->item_size);
+ t->index = index;
+ return t;
+ }
+ }
+
+ /* Check if we can add a block to the pool */
+ if (Tpool->AddBlockToPool()) return AllocateRaw(first);
+
+ return NULL;
+}
+
+#endif /* OLDPOOL_FUNC_H */