[Bf-blender-cvs] [6f2f808] master: GHash: use bool for comparison (simplify compare)

Campbell Barton noreply at git.blender.org
Wed Sep 24 22:20:08 CEST 2014


Commit: 6f2f80887b10f6a704a7394f0580e6ee39ea611d
Author: Campbell Barton
Date:   Thu Sep 25 06:15:52 2014 +1000
Branches: master
https://developer.blender.org/rB6f2f80887b10f6a704a7394f0580e6ee39ea611d

GHash: use bool for comparison (simplify compare)

===================================================================

M	source/blender/blenkernel/intern/cdderivedmesh.c
M	source/blender/blenkernel/intern/image.c
M	source/blender/blenkernel/intern/movieclip.c
M	source/blender/blenkernel/intern/node.c
M	source/blender/blenkernel/intern/seqcache.c
M	source/blender/blenkernel/intern/treehash.c
M	source/blender/blenlib/BLI_ghash.h
M	source/blender/blenlib/intern/BLI_args.c
M	source/blender/blenlib/intern/BLI_ghash.c
M	source/blender/editors/mesh/meshtools.c
M	source/blender/editors/sculpt_paint/sculpt_uv.c
M	source/blender/editors/uvedit/uvedit_smart_stitch.c
M	source/blender/imbuf/intern/cache.c
M	source/blender/imbuf/intern/colormanagement.c
M	source/blender/imbuf/intern/moviecache.c

===================================================================

diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c
index 23ffa53..3aba16d 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 805c125..b57d014 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 35bf453..e28adb7 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 0f86b55..3a7bfb0 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 97062f7..4268b33 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 a65bd28..866502c 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 dd3f62c..af26058 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 8bd35f6..49a3c46 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 74d7fdc..aa17ef3 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 

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list