Mercurial > hg > openttd
changeset 8847:748b998a108e draft
(svn r12599) -Codechange: force AllocateSafeRaw() to be linked to simplify compiler's decisions about inlining
author | smatz <smatz@openttd.org> |
---|---|
date | Sun, 06 Apr 2008 23:49:45 +0000 |
parents | 838e1d6a0321 |
children | 066a8010467f |
files | projects/openttd_vs80.vcproj projects/openttd_vs90.vcproj source.list src/cargopacket.cpp src/depot.cpp src/engine.cpp src/group_cmd.cpp src/industry_cmd.cpp src/oldpool.h src/oldpool_func.h src/order_cmd.cpp src/signs.cpp src/station_cmd.cpp src/town_cmd.cpp src/vehicle.cpp src/waypoint.cpp |
diffstat | 16 files changed, 57 insertions(+), 27 deletions(-) [+] |
line wrap: on
line diff
--- a/projects/openttd_vs80.vcproj +++ b/projects/openttd_vs80.vcproj @@ -1188,6 +1188,10 @@ > </File> <File + RelativePath=".\..\src\oldpool_func.h" + > + </File> + <File RelativePath=".\..\src\openttd.h" > </File>
--- a/projects/openttd_vs90.vcproj +++ b/projects/openttd_vs90.vcproj @@ -1185,6 +1185,10 @@ > </File> <File + RelativePath=".\..\src\oldpool_func.h" + > + </File> + <File RelativePath=".\..\src\openttd.h" > </File>
--- a/source.list +++ b/source.list @@ -205,6 +205,7 @@ sound/null_s.h video/null_v.h oldpool.h +oldpool_func.h openttd.h order_base.h order_func.h
--- a/src/cargopacket.cpp +++ b/src/cargopacket.cpp @@ -7,6 +7,7 @@ #include "station_base.h" #include "cargopacket.h" #include "saveload.h" +#include "oldpool_func.h" /* Initialize the cargopacket-pool */ DEFINE_OLD_POOL_GENERIC(CargoPacket, CargoPacket)
--- a/src/depot.cpp +++ b/src/depot.cpp @@ -9,6 +9,7 @@ #include "saveload.h" #include "order_func.h" #include "window_func.h" +#include "oldpool_func.h" #include "table/strings.h"
--- a/src/engine.cpp +++ b/src/engine.cpp @@ -25,6 +25,7 @@ #include "autoreplace_gui.h" #include "string_func.h" #include "settings_type.h" +#include "oldpool_func.h" #include "table/strings.h" #include "table/engines.h"
--- a/src/group_cmd.cpp +++ b/src/group_cmd.cpp @@ -22,6 +22,7 @@ #include "string_func.h" #include "player_func.h" #include "order_func.h" +#include "oldpool_func.h" #include "table/strings.h"
--- a/src/industry_cmd.cpp +++ b/src/industry_cmd.cpp @@ -37,6 +37,7 @@ #include "vehicle_func.h" #include "sound_func.h" #include "station_base.h" +#include "oldpool_func.h" #include "table/strings.h" #include "table/sprites.h"
--- a/src/oldpool.h +++ b/src/oldpool.h @@ -260,32 +260,7 @@ } private: - /** - * 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). - */ - static inline T *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; - } + static T *AllocateSafeRaw(uint &first); protected: /** @@ -346,7 +321,8 @@ #define DEFINE_OLD_POOL_GENERIC(name, type) \ OldMemoryPool<type> _##name##_pool( \ #name, name##_POOL_MAX_BLOCKS, name##_POOL_BLOCK_SIZE_BITS, sizeof(type), \ - PoolNewBlock<type, &_##name##_pool>, PoolCleanBlock<type, &_##name##_pool>); + PoolNewBlock<type, &_##name##_pool>, PoolCleanBlock<type, &_##name##_pool>); \ + template type *PoolItem<type, type##ID, &_##name##_pool>::AllocateSafeRaw(uint &first); #define STATIC_OLD_POOL(name, type, block_size_bits, max_blocks, new_block_proc, clean_block_proc) \
new file mode 100644 --- /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 */
--- a/src/order_cmd.cpp +++ b/src/order_cmd.cpp @@ -25,6 +25,7 @@ #include "newgrf_cargo.h" #include "timetable.h" #include "vehicle_func.h" +#include "oldpool_func.h" #include "table/strings.h"
--- a/src/signs.cpp +++ b/src/signs.cpp @@ -19,6 +19,7 @@ #include "window_func.h" #include "map_func.h" #include "string_func.h" +#include "oldpool_func.h" #include "table/strings.h"
--- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -42,6 +42,7 @@ #include "vehicle_func.h" #include "string_func.h" #include "signal_func.h" +#include "oldpool_func.h" #include "table/sprites.h" #include "table/strings.h"
--- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -40,6 +40,7 @@ #include "window_func.h" #include "string_func.h" #include "newgrf_cargo.h" +#include "oldpool_func.h" #include "table/strings.h" #include "table/sprites.h"