From 501d2443d03cce18985fab3ffad5d23238748f3e Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 30 Jun 2021 16:37:14 +1000 Subject: Cleanup: use const arguments for accessor functions --- source/blender/blenlib/BLI_dynstr.h | 6 ++-- source/blender/blenlib/BLI_edgehash.h | 22 ++++++++----- source/blender/blenlib/BLI_ghash.h | 30 ++++++++--------- source/blender/blenlib/BLI_mempool.h | 2 +- source/blender/blenlib/intern/BLI_dynstr.c | 8 ++--- source/blender/blenlib/intern/BLI_ghash.c | 50 ++++++++++++++--------------- source/blender/blenlib/intern/BLI_mempool.c | 2 +- source/blender/blenlib/intern/edgehash.c | 14 ++++---- 8 files changed, 70 insertions(+), 64 deletions(-) (limited to 'source/blender/blenlib') diff --git a/source/blender/blenlib/BLI_dynstr.h b/source/blender/blenlib/BLI_dynstr.h index 4733812746d..4df773c7cc6 100644 --- a/source/blender/blenlib/BLI_dynstr.h +++ b/source/blender/blenlib/BLI_dynstr.h @@ -53,9 +53,9 @@ void BLI_dynstr_appendf(DynStr *__restrict ds, const char *__restrict format, .. void BLI_dynstr_vappendf(DynStr *__restrict ds, const char *__restrict format, va_list args) ATTR_PRINTF_FORMAT(2, 0) ATTR_NONNULL(1, 2); -int BLI_dynstr_get_len(DynStr *ds) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); -char *BLI_dynstr_get_cstring(DynStr *ds) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); -void BLI_dynstr_get_cstring_ex(DynStr *__restrict ds, char *__restrict rets) ATTR_NONNULL(); +int BLI_dynstr_get_len(const DynStr *ds) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); +char *BLI_dynstr_get_cstring(const DynStr *ds) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); +void BLI_dynstr_get_cstring_ex(const DynStr *__restrict ds, char *__restrict rets) ATTR_NONNULL(); void BLI_dynstr_clear(DynStr *ds) ATTR_NONNULL(); void BLI_dynstr_free(DynStr *ds) ATTR_NONNULL(); diff --git a/source/blender/blenlib/BLI_edgehash.h b/source/blender/blenlib/BLI_edgehash.h index 184e3bb57e7..41f0d41d1e0 100644 --- a/source/blender/blenlib/BLI_edgehash.h +++ b/source/blender/blenlib/BLI_edgehash.h @@ -57,8 +57,10 @@ void BLI_edgehash_free(EdgeHash *eh, EdgeHashFreeFP free_value); void BLI_edgehash_print(EdgeHash *eh); void BLI_edgehash_insert(EdgeHash *eh, unsigned int v0, unsigned int v1, void *val); bool BLI_edgehash_reinsert(EdgeHash *eh, unsigned int v0, unsigned int v1, void *val); -void *BLI_edgehash_lookup(EdgeHash *eh, unsigned int v0, unsigned int v1) ATTR_WARN_UNUSED_RESULT; -void *BLI_edgehash_lookup_default(EdgeHash *eh, +void *BLI_edgehash_lookup(const EdgeHash *eh, + unsigned int v0, + unsigned int v1) ATTR_WARN_UNUSED_RESULT; +void *BLI_edgehash_lookup_default(const EdgeHash *eh, unsigned int v0, unsigned int v1, void *default_value) ATTR_WARN_UNUSED_RESULT; @@ -73,8 +75,10 @@ bool BLI_edgehash_remove(EdgeHash *eh, EdgeHashFreeFP free_value); void *BLI_edgehash_popkey(EdgeHash *eh, unsigned int v0, unsigned int v1) ATTR_WARN_UNUSED_RESULT; -bool BLI_edgehash_haskey(EdgeHash *eh, unsigned int v0, unsigned int v1) ATTR_WARN_UNUSED_RESULT; -int BLI_edgehash_len(EdgeHash *eh) ATTR_WARN_UNUSED_RESULT; +bool BLI_edgehash_haskey(const EdgeHash *eh, + unsigned int v0, + unsigned int v1) ATTR_WARN_UNUSED_RESULT; +int BLI_edgehash_len(const EdgeHash *eh) ATTR_WARN_UNUSED_RESULT; void BLI_edgehash_clear_ex(EdgeHash *eh, EdgeHashFreeFP free_value, const uint reserve); void BLI_edgehash_clear(EdgeHash *eh, EdgeHashFreeFP free_value); @@ -86,7 +90,7 @@ BLI_INLINE void BLI_edgehashIterator_step(EdgeHashIterator *ehi) { ehi->index++; } -BLI_INLINE bool BLI_edgehashIterator_isDone(EdgeHashIterator *ehi) +BLI_INLINE bool BLI_edgehashIterator_isDone(const EdgeHashIterator *ehi) { return ehi->index >= ehi->length; } @@ -128,10 +132,12 @@ typedef struct EdgeSetIterator { EdgeSet *BLI_edgeset_new_ex(const char *info, const unsigned int nentries_reserve) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT; EdgeSet *BLI_edgeset_new(const char *info) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT; -int BLI_edgeset_len(EdgeSet *es) ATTR_WARN_UNUSED_RESULT; +int BLI_edgeset_len(const EdgeSet *es) ATTR_WARN_UNUSED_RESULT; bool BLI_edgeset_add(EdgeSet *es, unsigned int v0, unsigned int v1); void BLI_edgeset_insert(EdgeSet *es, unsigned int v0, unsigned int v1); -bool BLI_edgeset_haskey(EdgeSet *es, unsigned int v0, unsigned int v1) ATTR_WARN_UNUSED_RESULT; +bool BLI_edgeset_haskey(const EdgeSet *es, + unsigned int v0, + unsigned int v1) ATTR_WARN_UNUSED_RESULT; void BLI_edgeset_free(EdgeSet *es); /* rely on inline api for now */ @@ -150,7 +156,7 @@ BLI_INLINE void BLI_edgesetIterator_step(EdgeSetIterator *esi) { esi->index++; } -BLI_INLINE bool BLI_edgesetIterator_isDone(EdgeSetIterator *esi) +BLI_INLINE bool BLI_edgesetIterator_isDone(const EdgeSetIterator *esi) { return esi->index >= esi->length; } diff --git a/source/blender/blenlib/BLI_ghash.h b/source/blender/blenlib/BLI_ghash.h index b53b8a433d2..e708b327bd4 100644 --- a/source/blender/blenlib/BLI_ghash.h +++ b/source/blender/blenlib/BLI_ghash.h @@ -87,7 +87,7 @@ GHash *BLI_ghash_new_ex(GHashHashFP hashfp, GHash *BLI_ghash_new(GHashHashFP hashfp, GHashCmpFP cmpfp, const char *info) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT; -GHash *BLI_ghash_copy(GHash *gh, +GHash *BLI_ghash_copy(const GHash *gh, GHashKeyCopyFP keycopyfp, GHashValCopyFP valcopyfp) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT; void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp); @@ -96,8 +96,8 @@ void BLI_ghash_insert(GHash *gh, void *key, void *val); bool BLI_ghash_reinsert( GHash *gh, void *key, void *val, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp); void *BLI_ghash_replace_key(GHash *gh, void *key); -void *BLI_ghash_lookup(GHash *gh, const void *key) ATTR_WARN_UNUSED_RESULT; -void *BLI_ghash_lookup_default(GHash *gh, +void *BLI_ghash_lookup(const GHash *gh, const void *key) ATTR_WARN_UNUSED_RESULT; +void *BLI_ghash_lookup_default(const GHash *gh, const void *key, void *val_default) ATTR_WARN_UNUSED_RESULT; void **BLI_ghash_lookup_p(GHash *gh, const void *key) ATTR_WARN_UNUSED_RESULT; @@ -116,10 +116,10 @@ void BLI_ghash_clear_ex(GHash *gh, void *BLI_ghash_popkey(GHash *gh, const void *key, GHashKeyFreeFP keyfreefp) ATTR_WARN_UNUSED_RESULT; -bool BLI_ghash_haskey(GHash *gh, const void *key) ATTR_WARN_UNUSED_RESULT; +bool BLI_ghash_haskey(const GHash *gh, const void *key) ATTR_WARN_UNUSED_RESULT; bool BLI_ghash_pop(GHash *gh, GHashIterState *state, void **r_key, void **r_val) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); -unsigned int BLI_ghash_len(GHash *gh) ATTR_WARN_UNUSED_RESULT; +unsigned int BLI_ghash_len(const GHash *gh) ATTR_WARN_UNUSED_RESULT; void BLI_ghash_flag_set(GHash *gh, unsigned int flag); void BLI_ghash_flag_clear(GHash *gh, unsigned int flag); @@ -138,7 +138,7 @@ void BLI_ghashIterator_step(GHashIterator *ghi); BLI_INLINE void *BLI_ghashIterator_getKey(GHashIterator *ghi) ATTR_WARN_UNUSED_RESULT; BLI_INLINE void *BLI_ghashIterator_getValue(GHashIterator *ghi) ATTR_WARN_UNUSED_RESULT; BLI_INLINE void **BLI_ghashIterator_getValue_p(GHashIterator *ghi) ATTR_WARN_UNUSED_RESULT; -BLI_INLINE bool BLI_ghashIterator_done(GHashIterator *ghi) ATTR_WARN_UNUSED_RESULT; +BLI_INLINE bool BLI_ghashIterator_done(const GHashIterator *ghi) ATTR_WARN_UNUSED_RESULT; struct _gh_Entry { void *next, *key, *val; @@ -155,7 +155,7 @@ BLI_INLINE void **BLI_ghashIterator_getValue_p(GHashIterator *ghi) { return &((struct _gh_Entry *)ghi->curEntry)->val; } -BLI_INLINE bool BLI_ghashIterator_done(GHashIterator *ghi) +BLI_INLINE bool BLI_ghashIterator_done(const GHashIterator *ghi) { return !ghi->curEntry; } @@ -202,8 +202,8 @@ GSet *BLI_gset_new_ex(GSetHashFP hashfp, GSet *BLI_gset_new(GSetHashFP hashfp, GSetCmpFP cmpfp, const char *info) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT; -GSet *BLI_gset_copy(GSet *gs, GSetKeyCopyFP keycopyfp) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT; -unsigned int BLI_gset_len(GSet *gs) ATTR_WARN_UNUSED_RESULT; +GSet *BLI_gset_copy(const GSet *gs, GSetKeyCopyFP keycopyfp) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT; +unsigned int BLI_gset_len(const GSet *gs) ATTR_WARN_UNUSED_RESULT; void BLI_gset_flag_set(GSet *gs, unsigned int flag); void BLI_gset_flag_clear(GSet *gs, unsigned int flag); void BLI_gset_free(GSet *gs, GSetKeyFreeFP keyfreefp); @@ -212,7 +212,7 @@ bool BLI_gset_add(GSet *gs, void *key); bool BLI_gset_ensure_p_ex(GSet *gs, const void *key, void ***r_key); bool BLI_gset_reinsert(GSet *gh, void *key, GSetKeyFreeFP keyfreefp); void *BLI_gset_replace_key(GSet *gs, void *key); -bool BLI_gset_haskey(GSet *gs, const void *key) ATTR_WARN_UNUSED_RESULT; +bool BLI_gset_haskey(const GSet *gs, const void *key) ATTR_WARN_UNUSED_RESULT; bool BLI_gset_pop(GSet *gs, GSetIterState *state, void **r_key) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); bool BLI_gset_remove(GSet *gs, const void *key, GSetKeyFreeFP keyfreefp); @@ -220,7 +220,7 @@ void BLI_gset_clear_ex(GSet *gs, GSetKeyFreeFP keyfreefp, const unsigned int nen void BLI_gset_clear(GSet *gs, GSetKeyFreeFP keyfreefp); /* When set's are used for key & value. */ -void *BLI_gset_lookup(GSet *gs, const void *key) ATTR_WARN_UNUSED_RESULT; +void *BLI_gset_lookup(const GSet *gs, const void *key) ATTR_WARN_UNUSED_RESULT; void *BLI_gset_pop_key(GSet *gs, const void *key) ATTR_WARN_UNUSED_RESULT; /** \} */ @@ -260,9 +260,9 @@ BLI_INLINE void BLI_gsetIterator_step(GSetIterator *gsi) { BLI_ghashIterator_step((GHashIterator *)gsi); } -BLI_INLINE bool BLI_gsetIterator_done(GSetIterator *gsi) +BLI_INLINE bool BLI_gsetIterator_done(const GSetIterator *gsi) { - return BLI_ghashIterator_done((GHashIterator *)gsi); + return BLI_ghashIterator_done((const GHashIterator *)gsi); } #define GSET_ITER(gs_iter_, gset_) \ @@ -282,8 +282,8 @@ BLI_INLINE bool BLI_gsetIterator_done(GSetIterator *gsi) /* For testing, debugging only */ #ifdef GHASH_INTERNAL_API -int BLI_ghash_buckets_len(GHash *gh); -int BLI_gset_buckets_len(GSet *gs); +int BLI_ghash_buckets_len(const GHash *gh); +int BLI_gset_buckets_len(const GSet *gs); double BLI_ghash_calc_quality_ex(GHash *gh, double *r_load, diff --git a/source/blender/blenlib/BLI_mempool.h b/source/blender/blenlib/BLI_mempool.h index 4d9381093c7..e5e0df02033 100644 --- a/source/blender/blenlib/BLI_mempool.h +++ b/source/blender/blenlib/BLI_mempool.h @@ -48,7 +48,7 @@ void BLI_mempool_free(BLI_mempool *pool, void *addr) ATTR_NONNULL(1, 2); void BLI_mempool_clear_ex(BLI_mempool *pool, const int totelem_reserve) ATTR_NONNULL(1); void BLI_mempool_clear(BLI_mempool *pool) ATTR_NONNULL(1); void BLI_mempool_destroy(BLI_mempool *pool) ATTR_NONNULL(1); -int BLI_mempool_len(BLI_mempool *pool) ATTR_NONNULL(1); +int BLI_mempool_len(const BLI_mempool *pool) ATTR_NONNULL(1); void *BLI_mempool_findelem(BLI_mempool *pool, unsigned int index) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1); diff --git a/source/blender/blenlib/intern/BLI_dynstr.c b/source/blender/blenlib/intern/BLI_dynstr.c index 5255e8b9902..86784557b25 100644 --- a/source/blender/blenlib/intern/BLI_dynstr.c +++ b/source/blender/blenlib/intern/BLI_dynstr.c @@ -283,7 +283,7 @@ void BLI_dynstr_appendf(DynStr *__restrict ds, const char *__restrict format, .. * \param ds: The DynStr of interest. * \return The length of \a ds. */ -int BLI_dynstr_get_len(DynStr *ds) +int BLI_dynstr_get_len(const DynStr *ds) { return ds->curlen; } @@ -296,10 +296,10 @@ int BLI_dynstr_get_len(DynStr *ds) * \param ds: The DynStr of interest. * \param rets: The string to fill. */ -void BLI_dynstr_get_cstring_ex(DynStr *__restrict ds, char *__restrict rets) +void BLI_dynstr_get_cstring_ex(const DynStr *__restrict ds, char *__restrict rets) { char *s; - DynStrElem *dse; + const DynStrElem *dse; for (s = rets, dse = ds->elems; dse; dse = dse->next) { int slen = strlen(dse->str); @@ -320,7 +320,7 @@ void BLI_dynstr_get_cstring_ex(DynStr *__restrict ds, char *__restrict rets) * \param ds: The DynStr of interest. * \return The contents of \a ds as a c-string. */ -char *BLI_dynstr_get_cstring(DynStr *ds) +char *BLI_dynstr_get_cstring(const DynStr *ds) { char *rets = MEM_mallocN(ds->curlen + 1, "dynstr_cstring"); BLI_dynstr_get_cstring_ex(ds, rets); diff --git a/source/blender/blenlib/intern/BLI_ghash.c b/source/blender/blenlib/intern/BLI_ghash.c index 82eac7e0b33..8463c0ec511 100644 --- a/source/blender/blenlib/intern/BLI_ghash.c +++ b/source/blender/blenlib/intern/BLI_ghash.c @@ -122,8 +122,8 @@ struct GHash { BLI_INLINE void ghash_entry_copy(GHash *gh_dst, Entry *dst, - GHash *gh_src, - Entry *src, + const GHash *gh_src, + const Entry *src, GHashKeyCopyFP keycopyfp, GHashValCopyFP valcopyfp) { @@ -143,7 +143,7 @@ BLI_INLINE void ghash_entry_copy(GHash *gh_dst, /** * Get the full hash for a key. */ -BLI_INLINE uint ghash_keyhash(GHash *gh, const void *key) +BLI_INLINE uint ghash_keyhash(const GHash *gh, const void *key) { return gh->hashfp(key); } @@ -151,7 +151,7 @@ BLI_INLINE uint ghash_keyhash(GHash *gh, const void *key) /** * Get the full hash for an entry. */ -BLI_INLINE uint ghash_entryhash(GHash *gh, const Entry *e) +BLI_INLINE uint ghash_entryhash(const GHash *gh, const Entry *e) { return gh->hashfp(e->key); } @@ -159,7 +159,7 @@ BLI_INLINE uint ghash_entryhash(GHash *gh, const Entry *e) /** * Get the bucket-index for an already-computed full hash. */ -BLI_INLINE uint ghash_bucket_index(GHash *gh, const uint hash) +BLI_INLINE uint ghash_bucket_index(const GHash *gh, const uint hash) { #ifdef GHASH_USE_MODULO_BUCKETS return hash % gh->nbuckets; @@ -171,7 +171,7 @@ BLI_INLINE uint ghash_bucket_index(GHash *gh, const uint hash) /** * Find the index of next used bucket, starting from \a curr_bucket (\a gh is assumed non-empty). */ -BLI_INLINE uint ghash_find_next_bucket_index(GHash *gh, uint curr_bucket) +BLI_INLINE uint ghash_find_next_bucket_index(const GHash *gh, uint curr_bucket) { if (curr_bucket >= gh->nbuckets) { curr_bucket = 0; @@ -381,7 +381,7 @@ BLI_INLINE void ghash_buckets_reset(GHash *gh, const uint nentries) * Takes hash and bucket_index arguments to avoid calling #ghash_keyhash and #ghash_bucket_index * multiple times. */ -BLI_INLINE Entry *ghash_lookup_entry_ex(GHash *gh, const void *key, const uint bucket_index) +BLI_INLINE Entry *ghash_lookup_entry_ex(const GHash *gh, const void *key, const uint bucket_index) { Entry *e; /* If we do not store GHash, not worth computing it for each entry here! @@ -422,7 +422,7 @@ BLI_INLINE Entry *ghash_lookup_entry_prev_ex(GHash *gh, /** * Internal lookup function. Only wraps #ghash_lookup_entry_ex */ -BLI_INLINE Entry *ghash_lookup_entry(GHash *gh, const void *key) +BLI_INLINE Entry *ghash_lookup_entry(const GHash *gh, const void *key) { const uint hash = ghash_keyhash(gh, key); const uint bucket_index = ghash_bucket_index(gh, hash); @@ -652,7 +652,7 @@ static void ghash_free_cb(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP va /** * Copy the GHash. */ -static GHash *ghash_copy(GHash *gh, GHashKeyCopyFP keycopyfp, GHashValCopyFP valcopyfp) +static GHash *ghash_copy(const GHash *gh, GHashKeyCopyFP keycopyfp, GHashValCopyFP valcopyfp) { GHash *gh_new; uint i; @@ -724,7 +724,7 @@ GHash *BLI_ghash_new(GHashHashFP hashfp, GHashCmpFP cmpfp, const char *info) * Copy given GHash. Keys and values are also copied if relevant callback is provided, * else pointers remain the same. */ -GHash *BLI_ghash_copy(GHash *gh, GHashKeyCopyFP keycopyfp, GHashValCopyFP valcopyfp) +GHash *BLI_ghash_copy(const GHash *gh, GHashKeyCopyFP keycopyfp, GHashValCopyFP valcopyfp) { return ghash_copy(gh, keycopyfp, valcopyfp); } @@ -741,7 +741,7 @@ void BLI_ghash_reserve(GHash *gh, const uint nentries_reserve) /** * \return size of the GHash. */ -uint BLI_ghash_len(GHash *gh) +uint BLI_ghash_len(const GHash *gh) { return gh->nentries; } @@ -800,7 +800,7 @@ void *BLI_ghash_replace_key(GHash *gh, void *key) * \note When NULL is a valid value, use #BLI_ghash_lookup_p to differentiate a missing key * from a key with a NULL value. (Avoids calling #BLI_ghash_haskey before #BLI_ghash_lookup) */ -void *BLI_ghash_lookup(GHash *gh, const void *key) +void *BLI_ghash_lookup(const GHash *gh, const void *key) { GHashEntry *e = (GHashEntry *)ghash_lookup_entry(gh, key); BLI_assert(!(gh->flag & GHASH_FLAG_IS_GSET)); @@ -810,7 +810,7 @@ void *BLI_ghash_lookup(GHash *gh, const void *key) /** * A version of #BLI_ghash_lookup which accepts a fallback argument. */ -void *BLI_ghash_lookup_default(GHash *gh, const void *key, void *val_default) +void *BLI_ghash_lookup_default(const GHash *gh, const void *key, void *val_default) { GHashEntry *e = (GHashEntry *)ghash_lookup_entry(gh, key); BLI_assert(!(gh->flag & GHASH_FLAG_IS_GSET)); @@ -938,7 +938,7 @@ void *BLI_ghash_popkey(GHash *gh, const void *key, GHashKeyFreeFP keyfreefp) /** * \return true if the \a key is in \a gh. */ -bool BLI_ghash_haskey(GHash *gh, const void *key) +bool BLI_ghash_haskey(const GHash *gh, const void *key) { return (ghash_lookup_entry(gh, key) != NULL); } @@ -1130,12 +1130,12 @@ GSet *BLI_gset_new(GSetHashFP hashfp, GSetCmpFP cmpfp, const char *info) /** * Copy given GSet. Keys are also copied if callback is provided, else pointers remain the same. */ -GSet *BLI_gset_copy(GSet *gs, GHashKeyCopyFP keycopyfp) +GSet *BLI_gset_copy(const GSet *gs, GHashKeyCopyFP keycopyfp) { - return (GSet *)ghash_copy((GHash *)gs, keycopyfp, NULL); + return (GSet *)ghash_copy((const GHash *)gs, keycopyfp, NULL); } -uint BLI_gset_len(GSet *gs) +uint BLI_gset_len(const GSet *gs) { return ((GHash *)gs)->nentries; } @@ -1172,7 +1172,7 @@ bool BLI_gset_ensure_p_ex(GSet *gs, const void *key, void ***r_key) { const uint hash = ghash_keyhash((GHash *)gs, key); const uint bucket_index = ghash_bucket_index((GHash *)gs, hash); - GSetEntry *e = (GSetEntry *)ghash_lookup_entry_ex((GHash *)gs, key, bucket_index); + GSetEntry *e = (GSetEntry *)ghash_lookup_entry_ex((const GHash *)gs, key, bucket_index); const bool haskey = (e != NULL); if (!haskey) { @@ -1213,9 +1213,9 @@ bool BLI_gset_remove(GSet *gs, const void *key, GSetKeyFreeFP keyfreefp) return BLI_ghash_remove((GHash *)gs, key, keyfreefp, NULL); } -bool BLI_gset_haskey(GSet *gs, const void *key) +bool BLI_gset_haskey(const GSet *gs, const void *key) { - return (ghash_lookup_entry((GHash *)gs, key) != NULL); + return (ghash_lookup_entry((const GHash *)gs, key) != NULL); } /** @@ -1277,9 +1277,9 @@ void BLI_gset_flag_clear(GSet *gs, uint flag) /** * Returns the pointer to the key if it's found. */ -void *BLI_gset_lookup(GSet *gs, const void *key) +void *BLI_gset_lookup(const GSet *gs, const void *key) { - Entry *e = ghash_lookup_entry((GHash *)gs, key); + Entry *e = ghash_lookup_entry((const GHash *)gs, key); return e ? e->key : NULL; } @@ -1311,13 +1311,13 @@ void *BLI_gset_pop_key(GSet *gs, const void *key) /** * \return number of buckets in the GHash. */ -int BLI_ghash_buckets_len(GHash *gh) +int BLI_ghash_buckets_len(const GHash *gh) { return (int)gh->nbuckets; } -int BLI_gset_buckets_len(GSet *gs) +int BLI_gset_buckets_len(const GSet *gs) { - return BLI_ghash_buckets_len((GHash *)gs); + return BLI_ghash_buckets_len((const GHash *)gs); } /** diff --git a/source/blender/blenlib/intern/BLI_mempool.c b/source/blender/blenlib/intern/BLI_mempool.c index d3000ef38e8..8196438eb25 100644 --- a/source/blender/blenlib/intern/BLI_mempool.c +++ b/source/blender/blenlib/intern/BLI_mempool.c @@ -452,7 +452,7 @@ void BLI_mempool_free(BLI_mempool *pool, void *addr) } } -int BLI_mempool_len(BLI_mempool *pool) +int BLI_mempool_len(const BLI_mempool *pool) { return (int)pool->totused; } diff --git a/source/blender/blenlib/intern/edgehash.c b/source/blender/blenlib/intern/edgehash.c index b8bf535a3b4..f95619803bf 100644 --- a/source/blender/blenlib/intern/edgehash.c +++ b/source/blender/blenlib/intern/edgehash.c @@ -193,7 +193,7 @@ BLI_INLINE EdgeHashEntry *edgehash_insert(EdgeHash *eh, Edge edge, void *value) } } -BLI_INLINE EdgeHashEntry *edgehash_lookup_entry(EdgeHash *eh, uint v0, uint v1) +BLI_INLINE EdgeHashEntry *edgehash_lookup_entry(const EdgeHash *eh, uint v0, uint v1) { Edge edge = init_edge(v0, v1); @@ -310,7 +310,7 @@ bool BLI_edgehash_reinsert(EdgeHash *eh, uint v0, uint v1, void *value) /** * A version of #BLI_edgehash_lookup which accepts a fallback argument. */ -void *BLI_edgehash_lookup_default(EdgeHash *eh, uint v0, uint v1, void *default_value) +void *BLI_edgehash_lookup_default(const EdgeHash *eh, uint v0, uint v1, void *default_value) { EdgeHashEntry *entry = edgehash_lookup_entry(eh, v0, v1); return entry ? entry->value : default_value; @@ -322,7 +322,7 @@ void *BLI_edgehash_lookup_default(EdgeHash *eh, uint v0, uint v1, void *default_ * to differentiate between key-value being NULL and * lack of key then see #BLI_edgehash_lookup_p(). */ -void *BLI_edgehash_lookup(EdgeHash *eh, uint v0, uint v1) +void *BLI_edgehash_lookup(const EdgeHash *eh, uint v0, uint v1) { EdgeHashEntry *entry = edgehash_lookup_entry(eh, v0, v1); return entry ? entry->value : NULL; @@ -423,7 +423,7 @@ void *BLI_edgehash_popkey(EdgeHash *eh, uint v0, uint v1) /** * Return boolean true/false if edge (v0,v1) in hash. */ -bool BLI_edgehash_haskey(EdgeHash *eh, uint v0, uint v1) +bool BLI_edgehash_haskey(const EdgeHash *eh, uint v0, uint v1) { return edgehash_lookup_entry(eh, v0, v1) != NULL; } @@ -431,7 +431,7 @@ bool BLI_edgehash_haskey(EdgeHash *eh, uint v0, uint v1) /** * Return number of keys in hash. */ -int BLI_edgehash_len(EdgeHash *eh) +int BLI_edgehash_len(const EdgeHash *eh) { return (int)eh->length; } @@ -533,7 +533,7 @@ void BLI_edgeset_free(EdgeSet *es) MEM_freeN(es); } -int BLI_edgeset_len(EdgeSet *es) +int BLI_edgeset_len(const EdgeSet *es) { return (int)es->length; } @@ -608,7 +608,7 @@ void BLI_edgeset_insert(EdgeSet *es, uint v0, uint v1) } } -bool BLI_edgeset_haskey(EdgeSet *es, uint v0, uint v1) +bool BLI_edgeset_haskey(const EdgeSet *es, uint v0, uint v1) { Edge edge = init_edge(v0, v1); -- cgit v1.2.3