summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsmatz <smatz@openttd.org>2009-06-09 23:22:37 +0000
committersmatz <smatz@openttd.org>2009-06-09 23:22:37 +0000
commitfd191dd616b85ca27f2ef838fc68b41fdae0eae0 (patch)
treeb532475fa382d741bdd09f3cc3fdbd17cd6605fc
parent1c5ca9822dee9192ea3681779dd267db007cc2fa (diff)
downloadopenttd-fd191dd616b85ca27f2ef838fc68b41fdae0eae0.tar.xz
(svn r16546) -Codechange: use array member instead of allocating in costructor and freeing in desctructor
-rw-r--r--src/misc/hashtable.hpp22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/misc/hashtable.hpp b/src/misc/hashtable.hpp
index 05430f446..2e524e632 100644
--- a/src/misc/hashtable.hpp
+++ b/src/misc/hashtable.hpp
@@ -12,7 +12,7 @@ struct CHashTableSlotT
Titem_ *m_pFirst;
- CHashTableSlotT() : m_pFirst(NULL) {}
+ FORCEINLINE CHashTableSlotT() : m_pFirst(NULL) {}
/** hash table slot helper - clears the slot by simple forgetting its items */
FORCEINLINE void Clear() {m_pFirst = NULL;}
@@ -133,19 +133,16 @@ protected:
* Titem contains pointer to the next item - GetHashNext(), SetHashNext() */
typedef CHashTableSlotT<Titem_> Slot;
- Slot *m_slots; // here we store our data (array of blobs)
- int m_num_items; // item counter
+ Slot m_slots[Tcapacity]; ///< here we store our data (array of blobs)
+ int m_num_items; ///< item counter
public:
/* default constructor */
- FORCEINLINE CHashTableT()
- {
- /* construct all slots */
- m_slots = new Slot[Tcapacity];
- m_num_items = 0;
- }
+ FORCEINLINE CHashTableT() :
+ m_num_items(0)
+ { }
- ~CHashTableT() {delete [] m_slots; m_num_items = 0; m_slots = NULL;}
+ FORCEINLINE ~CHashTableT() { }
protected:
/** static helper - return hash for the given key modulo number of slots */
@@ -168,7 +165,10 @@ public:
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();}
+ FORCEINLINE void Clear()
+ {
+ for (size_t i = 0; i < lengthof(m_slots); i++) m_slots[i].Clear();
+ }
/** const item search */
const Titem_ *Find(const Tkey& key) const