[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [56544] trunk/blender/source/blender/ blenlib: use unsigned int's for smallhash, avoids using ABS when converting an
Campbell Barton
ideasman42 at gmail.com
Wed May 8 14:54:07 CEST 2013
Revision: 56544
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=56544
Author: campbellbarton
Date: 2013-05-08 12:54:07 +0000 (Wed, 08 May 2013)
Log Message:
-----------
use unsigned int's for smallhash, avoids using ABS when converting an
int from a key.
Modified Paths:
--------------
trunk/blender/source/blender/blenlib/BLI_smallhash.h
trunk/blender/source/blender/blenlib/intern/BLI_ghash.c
trunk/blender/source/blender/blenlib/intern/edgehash.c
trunk/blender/source/blender/blenlib/intern/smallhash.c
Modified: trunk/blender/source/blender/blenlib/BLI_smallhash.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_smallhash.h 2013-05-08 12:53:52 UTC (rev 56543)
+++ trunk/blender/source/blender/blenlib/BLI_smallhash.h 2013-05-08 12:54:07 UTC (rev 56544)
@@ -49,9 +49,9 @@
SmallHashEntry _stacktable[SMSTACKSIZE];
SmallHashEntry _copytable[SMSTACKSIZE];
SmallHashEntry *stacktable, *copytable;
- int used;
- int curhash;
- int size;
+ unsigned int used;
+ unsigned int curhash;
+ unsigned int size;
} SmallHash;
typedef struct {
Modified: trunk/blender/source/blender/blenlib/intern/BLI_ghash.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/BLI_ghash.c 2013-05-08 12:53:52 UTC (rev 56543)
+++ trunk/blender/source/blender/blenlib/intern/BLI_ghash.c 2013-05-08 12:54:07 UTC (rev 56544)
@@ -42,7 +42,7 @@
#include "MEM_sys_types.h" /* for intptr_t support */
/***/
-unsigned int hashsizes[] = {
+const unsigned int hashsizes[] = {
5, 11, 17, 37, 67, 131, 257, 521, 1031, 2053, 4099, 8209,
16411, 32771, 65537, 131101, 262147, 524309, 1048583, 2097169,
4194319, 8388617, 16777259, 33554467, 67108879, 134217757,
Modified: trunk/blender/source/blender/blenlib/intern/edgehash.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/edgehash.c 2013-05-08 12:53:52 UTC (rev 56543)
+++ trunk/blender/source/blender/blenlib/intern/edgehash.c 2013-05-08 12:54:07 UTC (rev 56544)
@@ -41,7 +41,7 @@
#include "BLI_mempool.h"
/**************inlined code************/
-static unsigned int _ehash_hashsizes[] = {
+static const unsigned int _ehash_hashsizes[] = {
1, 3, 5, 11, 17, 37, 67, 131, 257, 521, 1031, 2053, 4099, 8209,
16411, 32771, 65537, 131101, 262147, 524309, 1048583, 2097169,
4194319, 8388617, 16777259, 33554467, 67108879, 134217757,
Modified: trunk/blender/source/blender/blenlib/intern/smallhash.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/smallhash.c 2013-05-08 12:53:52 UTC (rev 56543)
+++ trunk/blender/source/blender/blenlib/intern/smallhash.c 2013-05-08 12:54:07 UTC (rev 56544)
@@ -45,23 +45,14 @@
#ifdef __GNUC__
# pragma GCC diagnostic ignored "-Wstrict-overflow"
+# pragma GCC diagnostic error "-Wsign-conversion"
#endif
-BLI_INLINE int smhash_nonzero(const int n)
-{
- return n + !n;
-}
-
-BLI_INLINE int smhash_abs_i(const int n)
-{
- return (n > 0) ? n : -n;
-}
-
/* typically this re-assigns 'h' */
#define SMHASH_NEXT(h, hoff) ( \
- CHECK_TYPE_INLINE(&(h), int), \
- CHECK_TYPE_INLINE(&(hoff), int), \
- smhash_abs_i((h) + (((hoff) = smhash_nonzero((hoff) * 2) + 1), (hoff))) \
+ CHECK_TYPE_INLINE(&(h), unsigned int), \
+ CHECK_TYPE_INLINE(&(hoff), unsigned int), \
+ ((h) + (((hoff) = ((hoff) * 2) + 1), (hoff))) \
)
extern unsigned int hashsizes[];
@@ -94,10 +85,10 @@
void BLI_smallhash_insert(SmallHash *hash, uintptr_t key, void *item)
{
- int h, hoff = 1;
+ unsigned int h, hoff = 1;
if (hash->size < hash->used * 3) {
- int newsize = hashsizes[++hash->curhash];
+ unsigned int newsize = hashsizes[++hash->curhash];
SmallHashEntry *tmp;
int i = 0;
@@ -122,7 +113,7 @@
continue;
}
- h = ABS((int)(tmp[i].key));
+ h = (unsigned int)(tmp[i].key);
hoff = 1;
while (!ELEM(hash->table[h % newsize].val, SMHASH_CELL_UNUSED, SMHASH_CELL_FREE)) {
h = SMHASH_NEXT(h, hoff);
@@ -139,7 +130,7 @@
}
}
- h = ABS((int)key);
+ h = (unsigned int)(key);
hoff = 1;
while (!ELEM(hash->table[h % hash->size].val, SMHASH_CELL_UNUSED, SMHASH_CELL_FREE)) {
@@ -155,9 +146,9 @@
void BLI_smallhash_remove(SmallHash *hash, uintptr_t key)
{
- int h, hoff = 1;
+ unsigned int h, hoff = 1;
- h = ABS((int)key);
+ h = (unsigned int)(key);
while ((hash->table[h % hash->size].key != key) ||
(hash->table[h % hash->size].val == SMHASH_CELL_UNUSED))
@@ -176,10 +167,10 @@
void *BLI_smallhash_lookup(SmallHash *hash, uintptr_t key)
{
- int h, hoff = 1;
+ unsigned int h, hoff = 1;
void *v;
- h = ABS((int)key);
+ h = (unsigned int)(key);
while ((hash->table[h % hash->size].key != key) ||
(hash->table[h % hash->size].val == SMHASH_CELL_UNUSED))
@@ -202,8 +193,8 @@
int BLI_smallhash_haskey(SmallHash *hash, uintptr_t key)
{
- int h = ABS((int)key);
- int hoff = 1;
+ unsigned int h = (unsigned int)(key);
+ unsigned int hoff = 1;
while ((hash->table[h % hash->size].key != key) ||
(hash->table[h % hash->size].val == SMHASH_CELL_UNUSED))
@@ -220,7 +211,7 @@
int BLI_smallhash_count(SmallHash *hash)
{
- return hash->used;
+ return (int)hash->used;
}
void *BLI_smallhash_iternext(SmallHashIter *iter, uintptr_t *key)
More information about the Bf-blender-cvs
mailing list