mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-17 21:25:40 +00:00
(svn r7210) -CodeChange: [YAPF] the global cache object is now not destroyed/recreated whenever the cache is invalidated. It now supports Flush() method that is used instead. It should also fix mem-leak warning produced by valgrind (Tron)
This commit is contained in:
parent
7fe387708f
commit
75f99b0abb
@ -24,6 +24,8 @@ public:
|
||||
|
||||
/** implicit constructor */
|
||||
FORCEINLINE CArrayT() { }
|
||||
/** Clear (destroy) all items */
|
||||
FORCEINLINE void Clear() {m_a.Clear();}
|
||||
/** Return actual number of items */
|
||||
FORCEINLINE int Size() const
|
||||
{
|
||||
|
@ -51,12 +51,21 @@ struct CFixedSizeArrayT {
|
||||
// release one reference to the shared block
|
||||
if ((--RefCnt()) > 0) return; // and return if there is still some owner
|
||||
|
||||
Clear();
|
||||
// free the memory block occupied by items
|
||||
free(((int8*)m_items) - ThdrSize);
|
||||
m_items = NULL;
|
||||
}
|
||||
|
||||
/** Clear (destroy) all items */
|
||||
FORCEINLINE void Clear()
|
||||
{
|
||||
// walk through all allocated items backward and destroy them
|
||||
for (Titem* pItem = &m_items[Size() - 1]; pItem >= m_items; pItem--) {
|
||||
pItem->~Titem_();
|
||||
}
|
||||
free(((int8*)m_items) - ThdrSize);
|
||||
m_items = NULL;
|
||||
// number of items become zero
|
||||
SizeRef() = 0;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
@ -12,6 +12,9 @@ struct CHashTableSlotT
|
||||
|
||||
CHashTableSlotT() : m_pFirst(NULL) {}
|
||||
|
||||
/** hash table slot helper - clears the slot by simple forgetting its items */
|
||||
FORCEINLINE void Clear() {m_pFirst = NULL;}
|
||||
|
||||
/** hash table slot helper - linear search for item with given key through the given blob - const version */
|
||||
FORCEINLINE const Titem_* Find(const Key& key) const
|
||||
{
|
||||
@ -162,6 +165,9 @@ public:
|
||||
/** item count */
|
||||
FORCEINLINE int Count() const {return m_num_items;}
|
||||
|
||||
/** simple clear - forget all items - used by CSegmentCostCacheT.Flush() */
|
||||
FORCEINLINE void Clear() const {for (int i = 0; i < Tcapacity; i++) m_slots[i].Clear();}
|
||||
|
||||
/** const item search */
|
||||
const Titem_* Find(const Tkey& key) const
|
||||
{
|
||||
|
@ -104,6 +104,9 @@ struct CSegmentCostCacheT
|
||||
|
||||
FORCEINLINE CSegmentCostCacheT() {}
|
||||
|
||||
/** flush (clear) the cache */
|
||||
FORCEINLINE void Flush() {m_map.Clear(); m_heap.Clear();};
|
||||
|
||||
FORCEINLINE Tsegment& Get(Key& key, bool *found)
|
||||
{
|
||||
Tsegment* item = m_map.Find(key);
|
||||
@ -143,12 +146,11 @@ protected:
|
||||
/// to access inherited path finder
|
||||
FORCEINLINE Tpf& Yapf() {return *static_cast<Tpf*>(this);}
|
||||
|
||||
FORCEINLINE static Cache*& stGlobalCachePtr() {static Cache* pC = NULL; return pC;}
|
||||
|
||||
FORCEINLINE static Cache& stGetGlobalCache()
|
||||
{
|
||||
static int last_rail_change_counter = 0;
|
||||
static Date last_date = 0;
|
||||
static Cache C;
|
||||
|
||||
// some statistics
|
||||
if (last_date != _date) {
|
||||
@ -157,18 +159,12 @@ protected:
|
||||
_total_pf_time_us = 0;
|
||||
}
|
||||
|
||||
Cache*& pC = stGlobalCachePtr();
|
||||
|
||||
// delete the cache sometimes...
|
||||
if (pC != NULL && last_rail_change_counter != Cache::s_rail_change_counter) {
|
||||
if (last_rail_change_counter != Cache::s_rail_change_counter) {
|
||||
last_rail_change_counter = Cache::s_rail_change_counter;
|
||||
delete pC;
|
||||
pC = NULL;
|
||||
C.Flush();
|
||||
}
|
||||
|
||||
if (pC == NULL)
|
||||
pC = new Cache();
|
||||
return *pC;
|
||||
return C;
|
||||
}
|
||||
|
||||
public:
|
||||
|
Loading…
Reference in New Issue
Block a user