From 6f2f80887b10f6a704a7394f0580e6ee39ea611d Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 25 Sep 2014 06:15:52 +1000 Subject: GHash: use bool for comparison (simplify compare) --- source/blender/blenkernel/intern/cdderivedmesh.c | 2 +- source/blender/blenkernel/intern/image.c | 4 +- source/blender/blenkernel/intern/movieclip.c | 21 +----- source/blender/blenkernel/intern/node.c | 10 +-- source/blender/blenkernel/intern/seqcache.c | 87 ++++------------------ source/blender/blenkernel/intern/treehash.c | 2 +- source/blender/blenlib/BLI_ghash.h | 12 +-- source/blender/blenlib/intern/BLI_args.c | 12 +-- source/blender/blenlib/intern/BLI_ghash.c | 30 +++----- source/blender/editors/mesh/meshtools.c | 2 +- source/blender/editors/sculpt_paint/sculpt_uv.c | 2 +- .../blender/editors/uvedit/uvedit_smart_stitch.c | 2 +- source/blender/imbuf/intern/cache.c | 16 ++-- source/blender/imbuf/intern/colormanagement.c | 15 +--- source/blender/imbuf/intern/moviecache.c | 2 +- 15 files changed, 63 insertions(+), 156 deletions(-) (limited to 'source') diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c index 23ffa53a096..3aba16ddc38 100644 --- a/source/blender/blenkernel/intern/cdderivedmesh.c +++ b/source/blender/blenkernel/intern/cdderivedmesh.c @@ -2717,7 +2717,7 @@ static unsigned int poly_gset_hash_fn(const void *key) return pk->hash_sum; } -static int poly_gset_compare_fn(const void *k1, const void *k2) +static bool poly_gset_compare_fn(const void *k1, const void *k2) { const PolyKey *pk1 = k1; const PolyKey *pk2 = k2; diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c index 805c1250c5d..b57d0143b9b 100644 --- a/source/blender/blenkernel/intern/image.c +++ b/source/blender/blenkernel/intern/image.c @@ -120,12 +120,12 @@ static unsigned int imagecache_hashhash(const void *key_v) return key->index; } -static int imagecache_hashcmp(const void *a_v, const void *b_v) +static bool imagecache_hashcmp(const void *a_v, const void *b_v) { const ImageCacheKey *a = (ImageCacheKey *) a_v; const ImageCacheKey *b = (ImageCacheKey *) b_v; - return a->index - b->index; + return (a->index != b->index); } static void imagecache_keydata(void *userkey, int *framenr, int *proxy, int *render_flags) diff --git a/source/blender/blenkernel/intern/movieclip.c b/source/blender/blenkernel/intern/movieclip.c index 35bf453c328..e28adb7c0e0 100644 --- a/source/blender/blenkernel/intern/movieclip.c +++ b/source/blender/blenkernel/intern/movieclip.c @@ -406,27 +406,14 @@ static unsigned int moviecache_hashhash(const void *keyv) return rval; } -static int moviecache_hashcmp(const void *av, const void *bv) +static bool moviecache_hashcmp(const void *av, const void *bv) { const MovieClipImBufCacheKey *a = (MovieClipImBufCacheKey *)av; const MovieClipImBufCacheKey *b = (MovieClipImBufCacheKey *)bv; - if (a->framenr < b->framenr) - return -1; - else if (a->framenr > b->framenr) - return 1; - - if (a->proxy < b->proxy) - return -1; - else if (a->proxy > b->proxy) - return 1; - - if (a->render_flag < b->render_flag) - return -1; - else if (a->render_flag > b->render_flag) - return 1; - - return 0; + return ((a->framenr != b->framenr) || + (a->proxy != b->proxy) || + (a->render_flag != b->render_flag)); } static void *moviecache_getprioritydata(void *key_v) diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c index 0f86b551092..3a7bfb03e07 100644 --- a/source/blender/blenkernel/intern/node.c +++ b/source/blender/blenkernel/intern/node.c @@ -2682,16 +2682,12 @@ static unsigned int node_instance_hash_key(const void *key) return ((const bNodeInstanceKey *)key)->value; } -static int node_instance_hash_key_cmp(const void *a, const void *b) +static bool node_instance_hash_key_cmp(const void *a, const void *b) { unsigned int value_a = ((const bNodeInstanceKey *)a)->value; unsigned int value_b = ((const bNodeInstanceKey *)b)->value; - if (value_a == value_b) - return 0; - else if (value_a < value_b) - return -1; - else - return 1; + + return (value_a != value_b); } bNodeInstanceHash *BKE_node_instance_hash_new(const char *info) diff --git a/source/blender/blenkernel/intern/seqcache.c b/source/blender/blenkernel/intern/seqcache.c index 97062f728c5..4268b33cb14 100644 --- a/source/blender/blenkernel/intern/seqcache.c +++ b/source/blender/blenkernel/intern/seqcache.c @@ -69,58 +69,15 @@ static struct SeqPreprocessCache *preprocess_cache = NULL; static void preprocessed_cache_destruct(void); -static int seq_cmp_render_data(const SeqRenderData *a, const SeqRenderData *b) +static bool seq_cmp_render_data(const SeqRenderData *a, const SeqRenderData *b) { - if (a->preview_render_size < b->preview_render_size) { - return -1; - } - if (a->preview_render_size > b->preview_render_size) { - return 1; - } - - if (a->rectx < b->rectx) { - return -1; - } - if (a->rectx > b->rectx) { - return 1; - } - - if (a->recty < b->recty) { - return -1; - } - if (a->recty > b->recty) { - return 1; - } - - if (a->bmain < b->bmain) { - return -1; - } - if (a->bmain > b->bmain) { - return 1; - } - - if (a->scene < b->scene) { - return -1; - } - if (a->scene > b->scene) { - return 1; - } - - if (a->motion_blur_shutter < b->motion_blur_shutter) { - return -1; - } - if (a->motion_blur_shutter > b->motion_blur_shutter) { - return 1; - } - - if (a->motion_blur_samples < b->motion_blur_samples) { - return -1; - } - if (a->motion_blur_samples > b->motion_blur_samples) { - return 1; - } - - return 0; + return ((a->preview_render_size != b->preview_render_size) || + (a->rectx != b->rectx) || + (a->recty != b->recty) || + (a->bmain != b->bmain) || + (a->scene != b->scene) || + (a->motion_blur_shutter != b->motion_blur_shutter) || + (a->motion_blur_samples != b->motion_blur_samples)); } static unsigned int seq_hash_render_data(const SeqRenderData *a) @@ -148,33 +105,15 @@ static unsigned int seqcache_hashhash(const void *key_) return rval; } -static int seqcache_hashcmp(const void *a_, const void *b_) +static bool seqcache_hashcmp(const void *a_, const void *b_) { const SeqCacheKey *a = (SeqCacheKey *) a_; const SeqCacheKey *b = (SeqCacheKey *) b_; - if (a->seq < b->seq) { - return -1; - } - if (a->seq > b->seq) { - return 1; - } - - if (a->cfra < b->cfra) { - return -1; - } - if (a->cfra > b->cfra) { - return 1; - } - - if (a->type < b->type) { - return -1; - } - if (a->type > b->type) { - return 1; - } - - return seq_cmp_render_data(&a->context, &b->context); + return ((a->seq != b->seq) || + (a->cfra != b->cfra) || + (a->type != b->type) || + seq_cmp_render_data(&a->context, &b->context)); } void BKE_sequencer_cache_destruct(void) diff --git a/source/blender/blenkernel/intern/treehash.c b/source/blender/blenkernel/intern/treehash.c index a65bd28da97..866502c4ae1 100644 --- a/source/blender/blenkernel/intern/treehash.c +++ b/source/blender/blenkernel/intern/treehash.c @@ -91,7 +91,7 @@ static unsigned int tse_hash(const void *ptr) return hash.u_int; } -static int tse_cmp(const void *a, const void *b) +static bool tse_cmp(const void *a, const void *b) { const TreeStoreElem *tse_a = a; const TreeStoreElem *tse_b = b; diff --git a/source/blender/blenlib/BLI_ghash.h b/source/blender/blenlib/BLI_ghash.h index dd3f62cd6d3..af2605894e3 100644 --- a/source/blender/blenlib/BLI_ghash.h +++ b/source/blender/blenlib/BLI_ghash.h @@ -41,7 +41,7 @@ extern "C" { #endif typedef unsigned int (*GHashHashFP) (const void *key); -typedef int (*GHashCmpFP) (const void *a, const void *b); +typedef bool (*GHashCmpFP) (const void *a, const void *b); typedef void (*GHashKeyFreeFP) (void *key); typedef void (*GHashValFreeFP) (void *val); @@ -120,14 +120,14 @@ BLI_INLINE bool BLI_ghashIterator_done(GHashIterator *ghi) { return !ghi * \{ */ unsigned int BLI_ghashutil_ptrhash(const void *key); -int BLI_ghashutil_ptrcmp(const void *a, const void *b); +bool BLI_ghashutil_ptrcmp(const void *a, const void *b); unsigned int BLI_ghashutil_strhash_n(const char *key, size_t n); #define BLI_ghashutil_strhash(key) ( \ CHECK_TYPE_INLINE(key, char *), \ BLI_ghashutil_strhash_p(key)) unsigned int BLI_ghashutil_strhash_p(const void *key); -int BLI_ghashutil_strcmp(const void *a, const void *b); +bool BLI_ghashutil_strcmp(const void *a, const void *b); #define BLI_ghashutil_inthash(key) ( \ CHECK_TYPE_INLINE(&(key), int *), \ @@ -139,11 +139,11 @@ unsigned int BLI_ghashutil_uinthash(unsigned int key); unsigned int BLI_ghashutil_uinthash_v4(const unsigned int key[4]); #define BLI_ghashutil_inthash_v4_p \ ((GSetHashFP)BLI_ghashutil_uinthash_v4) -int BLI_ghashutil_uinthash_v4_cmp(const void *a, const void *b); +bool BLI_ghashutil_uinthash_v4_cmp(const void *a, const void *b); #define BLI_ghashutil_inthash_v4_cmp \ BLI_ghashutil_uinthash_v4_cmp unsigned int BLI_ghashutil_inthash_p(const void *ptr); -int BLI_ghashutil_intcmp(const void *a, const void *b); +bool BLI_ghashutil_intcmp(const void *a, const void *b); /** \} */ @@ -167,7 +167,7 @@ typedef struct GHashPair { GHashPair *BLI_ghashutil_pairalloc(const void *first, const void *second); unsigned int BLI_ghashutil_pairhash(const void *ptr); -int BLI_ghashutil_paircmp(const void *a, const void *b); +bool BLI_ghashutil_paircmp(const void *a, const void *b); void BLI_ghashutil_pairfree(void *ptr); diff --git a/source/blender/blenlib/intern/BLI_args.c b/source/blender/blenlib/intern/BLI_args.c index 8bd35f651b7..49a3c466727 100644 --- a/source/blender/blenlib/intern/BLI_args.c +++ b/source/blender/blenlib/intern/BLI_args.c @@ -91,15 +91,17 @@ static unsigned int keyhash(const void *ptr) return case_strhash(k->arg); /* ^ BLI_ghashutil_inthash((void *)k->pass); */ } -static int keycmp(const void *a, const void *b) +static bool keycmp(const void *a, const void *b) { const bAKey *ka = a; const bAKey *kb = b; if (ka->pass == kb->pass || ka->pass == -1 || kb->pass == -1) { /* -1 is wildcard for pass */ - if (ka->case_str == 1 || kb->case_str == 1) - return BLI_strcasecmp(ka->arg, kb->arg); - else - return strcmp(ka->arg, kb->arg); + if (ka->case_str == 1 || kb->case_str == 1) { + return (BLI_strcasecmp(ka->arg, kb->arg) != 0); + } + else { + return (strcmp(ka->arg, kb->arg) != 0); + } } else { return BLI_ghashutil_intcmp((const void *)ka->pass, (const void *)kb->pass); diff --git a/source/blender/blenlib/intern/BLI_ghash.c b/source/blender/blenlib/intern/BLI_ghash.c index 74d7fdc88cb..aa17ef393c9 100644 --- a/source/blender/blenlib/intern/BLI_ghash.c +++ b/source/blender/blenlib/intern/BLI_ghash.c @@ -683,12 +683,9 @@ unsigned int BLI_ghashutil_ptrhash(const void *key) return (unsigned int)y; } #endif -int BLI_ghashutil_ptrcmp(const void *a, const void *b) +bool BLI_ghashutil_ptrcmp(const void *a, const void *b) { - if (a == b) - return 0; - else - return (a < b) ? -1 : 1; + return (a != b); } unsigned int BLI_ghashutil_uinthash_v4(const unsigned int key[4]) @@ -704,9 +701,9 @@ unsigned int BLI_ghashutil_uinthash_v4(const unsigned int key[4]) return hash; } -int BLI_ghashutil_uinthash_v4_cmp(const void *a, const void *b) +bool BLI_ghashutil_uinthash_v4_cmp(const void *a, const void *b) { - return memcmp(a, b, sizeof(unsigned int[4])); + return (memcmp(a, b, sizeof(unsigned int[4])) != 0); } unsigned int BLI_ghashutil_uinthash(unsigned int key) @@ -735,12 +732,9 @@ unsigned int BLI_ghashutil_inthash_p(const void *ptr) return (unsigned int)(key & 0xffffffff); } -int BLI_ghashutil_intcmp(const void *a, const void *b) +bool BLI_ghashutil_intcmp(const void *a, const void *b) { - if (a == b) - return 0; - else - return (a < b) ? -1 : 1; + return (a != b); } /** @@ -774,9 +768,9 @@ unsigned int BLI_ghashutil_strhash_p(const void *ptr) return h; } -int BLI_ghashutil_strcmp(const void *a, const void *b) +bool BLI_ghashutil_strcmp(const void *a, const void *b) { - return strcmp(a, b); + return (strcmp(a, b) != 0); } GHashPair *BLI_ghashutil_pairalloc(const void *first, const void *second) @@ -794,15 +788,13 @@ unsigned int BLI_ghashutil_pairhash(const void *ptr) return hash ^ BLI_ghashutil_ptrhash(pair->second); } -int BLI_ghashutil_paircmp(const void *a, const void *b) +bool BLI_ghashutil_paircmp(const void *a, const void *b) { const GHashPair *A = a; const GHashPair *B = b; - int cmp = BLI_ghashutil_ptrcmp(A->first, B->first); - if (cmp == 0) - return BLI_ghashutil_ptrcmp(A->second, B->second); - return cmp; + return (BLI_ghashutil_ptrcmp(A->first, B->first) || + BLI_ghashutil_ptrcmp(A->second, B->second)); } void BLI_ghashutil_pairfree(void *ptr) diff --git a/source/blender/editors/mesh/meshtools.c b/source/blender/editors/mesh/meshtools.c index d252ae20270..16f4f61f92b 100644 --- a/source/blender/editors/mesh/meshtools.c +++ b/source/blender/editors/mesh/meshtools.c @@ -999,7 +999,7 @@ static int mirror_facerotation(MFace *a, MFace *b) return -1; } -static int mirror_facecmp(const void *a, const void *b) +static bool mirror_facecmp(const void *a, const void *b) { return (mirror_facerotation((MFace *)a, (MFace *)b) == -1); } diff --git a/source/blender/editors/sculpt_paint/sculpt_uv.c b/source/blender/editors/sculpt_paint/sculpt_uv.c index 5b46e5c3a59..d90eaafa379 100644 --- a/source/blender/editors/sculpt_paint/sculpt_uv.c +++ b/source/blender/editors/sculpt_paint/sculpt_uv.c @@ -563,7 +563,7 @@ static unsigned int uv_edge_hash(const void *key) BLI_ghashutil_uinthash(edge->uv1)); } -static int uv_edge_compare(const void *a, const void *b) +static bool uv_edge_compare(const void *a, const void *b) { UvEdge *edge1 = (UvEdge *)a; UvEdge *edge2 = (UvEdge *)b; diff --git a/source/blender/editors/uvedit/uvedit_smart_stitch.c b/source/blender/editors/uvedit/uvedit_smart_stitch.c index ba4b65f4ed4..fcd5267fd44 100644 --- a/source/blender/editors/uvedit/uvedit_smart_stitch.c +++ b/source/blender/editors/uvedit/uvedit_smart_stitch.c @@ -1360,7 +1360,7 @@ static unsigned int uv_edge_hash(const void *key) BLI_ghashutil_uinthash(edge->uv1); } -static int uv_edge_compare(const void *a, const void *b) +static bool uv_edge_compare(const void *a, const void *b) { UvEdge *edge1 = (UvEdge *)a; UvEdge *edge2 = (UvEdge *)b; diff --git a/source/blender/imbuf/intern/cache.c b/source/blender/imbuf/intern/cache.c index 0c17dd21434..677c3dbe700 100644 --- a/source/blender/imbuf/intern/cache.c +++ b/source/blender/imbuf/intern/cache.c @@ -101,14 +101,14 @@ static unsigned int imb_global_tile_hash(const void *gtile_p) return ((unsigned int)(intptr_t)gtile->ibuf) * 769 + gtile->tx * 53 + gtile->ty * 97; } -static int imb_global_tile_cmp(const void *a_p, const void *b_p) +static bool imb_global_tile_cmp(const void *a_p, const void *b_p) { const ImGlobalTile *a = a_p; const ImGlobalTile *b = b_p; - if (a->ibuf == b->ibuf && a->tx == b->tx && a->ty == b->ty) return 0; - else if (a->ibuf < b->ibuf || a->tx < b->tx || a->ty < b->ty) return -1; - else return 1; + return ((a->ibuf != b->ibuf) || + (a->tx != b->tx) || + (a->ty != b->ty)); } static unsigned int imb_thread_tile_hash(const void *ttile_p) @@ -118,14 +118,14 @@ static unsigned int imb_thread_tile_hash(const void *ttile_p) return ((unsigned int)(intptr_t)ttile->ibuf) * 769 + ttile->tx * 53 + ttile->ty * 97; } -static int imb_thread_tile_cmp(const void *a_p, const void *b_p) +static bool imb_thread_tile_cmp(const void *a_p, const void *b_p) { const ImThreadTile *a = a_p; const ImThreadTile *b = b_p; - if (a->ibuf == b->ibuf && a->tx == b->tx && a->ty == b->ty) return 0; - else if (a->ibuf < b->ibuf || a->tx < b->tx || a->ty < b->ty) return -1; - else return 1; + return ((a->ibuf != b->ibuf) || + (a->tx != b->tx) || + (a->ty != b->ty)); } /******************************** Load/Unload ********************************/ diff --git a/source/blender/imbuf/intern/colormanagement.c b/source/blender/imbuf/intern/colormanagement.c index 06dd128137b..5dd6b366a93 100644 --- a/source/blender/imbuf/intern/colormanagement.c +++ b/source/blender/imbuf/intern/colormanagement.c @@ -252,22 +252,13 @@ static unsigned int colormanage_hashhash(const void *key_v) return rval; } -static int colormanage_hashcmp(const void *av, const void *bv) +static bool colormanage_hashcmp(const void *av, const void *bv) { const ColormanageCacheKey *a = (ColormanageCacheKey *) av; const ColormanageCacheKey *b = (ColormanageCacheKey *) bv; - if (a->view < b->view) - return -1; - else if (a->view > b->view) - return 1; - - if (a->display < b->display) - return -1; - else if (a->display > b->display) - return 1; - - return 0; + return ((a->view != b->view) || + (a->display != b->display)); } static struct MovieCache *colormanage_moviecache_ensure(ImBuf *ibuf) diff --git a/source/blender/imbuf/intern/moviecache.c b/source/blender/imbuf/intern/moviecache.c index ea75673e5f0..1641bd3089b 100644 --- a/source/blender/imbuf/intern/moviecache.c +++ b/source/blender/imbuf/intern/moviecache.c @@ -104,7 +104,7 @@ static unsigned int moviecache_hashhash(const void *keyv) return key->cache_owner->hashfp(key->userkey); } -static int moviecache_hashcmp(const void *av, const void *bv) +static bool moviecache_hashcmp(const void *av, const void *bv) { const MovieCacheKey *a = (MovieCacheKey *)av; const MovieCacheKey *b = (MovieCacheKey *)bv; -- cgit v1.2.3