--- deliantra/server/include/util.h 2012/10/29 23:55:54 1.120 +++ deliantra/server/include/util.h 2012/11/12 02:39:51 1.122 @@ -239,9 +239,9 @@ #else // and has a max. error of 9 in the range -100..+100. #endif -inline int +inline int idistance (int dx, int dy) -{ +{ unsigned int dx_ = abs (dx); unsigned int dy_ = abs (dy); @@ -409,7 +409,7 @@ typedef const Tp &const_reference; typedef Tp value_type; - template + template struct rebind { typedef slice_allocator other; @@ -462,7 +462,7 @@ refcnt_buf (const refcnt_buf &src) { data = src.data; - ++_refcnt (); + inc (); } ~refcnt_buf (); @@ -481,30 +481,37 @@ protected: enum { - overhead = sizeof (unsigned int) * 2 + overhead = sizeof (uint32_t) * 2 }; - unsigned int &_size () const + uint32_t &_size () const { return ((unsigned int *)data)[-2]; } - unsigned int &_refcnt () const + uint32_t &_refcnt () const { return ((unsigned int *)data)[-1]; } - void _alloc (unsigned int size) + void _alloc (uint32_t size) { data = ((char *)salloc (size + overhead)) + overhead; _size () = size; _refcnt () = 1; } + void _dealloc (); + + void inc () + { + ++_refcnt (); + } + void dec () { if (!--_refcnt ()) - sfree (data - overhead, size () + overhead); + _dealloc (); } }; @@ -592,7 +599,7 @@ // runs concurrently with the looping logic. // we modify the hash a bit to improve its distribution uint32_t hash = STRHSH_NULL; - + while (*s) hash = (hash ^ *s++) * 16777619U; @@ -603,7 +610,7 @@ memhsh (const char *s, size_t len) { uint32_t hash = STRHSH_NULL; - + while (len--) hash = (hash ^ *s++) * 16777619U;