GHash: use bool for comparison (simplify compare)
This commit is contained in:
parent
faaf0c719f
commit
6f2f80887b
Notes:
blender-bot
2023-02-14 10:01:17 +01:00
Referenced by issue #42021, Cycles OSL renders a black image
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 ********************************/
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue