Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2013-05-08 16:54:07 +0400
committerCampbell Barton <ideasman42@gmail.com>2013-05-08 16:54:07 +0400
commit62db610220867bb2b68a338b5fb8a2893f45fa80 (patch)
treef80ef9ab7d804e9bd0e31d6b8b2b155e1c164441 /source/blender/blenlib/intern/smallhash.c
parent6b1b20ef0d17156c82a68d39142c41a24c1c5d47 (diff)
use unsigned int's for smallhash, avoids using ABS when converting an
int from a key.
Diffstat (limited to 'source/blender/blenlib/intern/smallhash.c')
-rw-r--r--source/blender/blenlib/intern/smallhash.c39
1 files changed, 15 insertions, 24 deletions
diff --git a/source/blender/blenlib/intern/smallhash.c b/source/blender/blenlib/intern/smallhash.c
index c24b495bfb6..600433fe1b1 100644
--- a/source/blender/blenlib/intern/smallhash.c
+++ b/source/blender/blenlib/intern/smallhash.c
@@ -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_release(SmallHash *hash)
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 @@ void BLI_smallhash_insert(SmallHash *hash, uintptr_t key, void *item)
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 @@ void BLI_smallhash_insert(SmallHash *hash, uintptr_t key, void *item)
}
}
- 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_insert(SmallHash *hash, uintptr_t key, void *item)
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_remove(SmallHash *hash, uintptr_t key)
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 @@ void *BLI_smallhash_lookup(SmallHash *hash, uintptr_t key)
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_haskey(SmallHash *hash, uintptr_t key)
int BLI_smallhash_count(SmallHash *hash)
{
- return hash->used;
+ return (int)hash->used;
}
void *BLI_smallhash_iternext(SmallHashIter *iter, uintptr_t *key)