diff options
author | KUDr <kudr@openttd.org> | 2006-11-18 19:20:47 +0000 |
---|---|---|
committer | KUDr <kudr@openttd.org> | 2006-11-18 19:20:47 +0000 |
commit | 9b81f084af2a19da3487fa747bc40f2c4b876845 (patch) | |
tree | 0dcbe68a8fa0166ef30d7a7f8870a502837bfa23 /yapf/yapf_costcache.hpp | |
parent | 3f64e50fc9a8f336fae1e59adabf604d8778cd4e (diff) | |
download | openttd-9b81f084af2a19da3487fa747bc40f2c4b876845.tar.xz |
(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)
Diffstat (limited to 'yapf/yapf_costcache.hpp')
-rw-r--r-- | yapf/yapf_costcache.hpp | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/yapf/yapf_costcache.hpp b/yapf/yapf_costcache.hpp index 8e99219cc..4d1f5ea0f 100644 --- a/yapf/yapf_costcache.hpp +++ b/yapf/yapf_costcache.hpp @@ -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: |