[Bf-blender-cvs] [a47e425] temp-ghash-basis: Make ghash_copy do actual exact copy (same number of buckets).
Bastien Montagne
noreply at git.blender.org
Thu Mar 19 17:22:29 CET 2015
Commit: a47e4258f813de200b923ae10c4790d81962a2b3
Author: Bastien Montagne
Date: Thu Mar 19 17:21:38 2015 +0100
Branches: temp-ghash-basis
https://developer.blender.org/rBa47e4258f813de200b923ae10c4790d81962a2b3
Make ghash_copy do actual exact copy (same number of buckets).
Simplifies copy code (no need to re-compute compute hash of entries).
===================================================================
M source/blender/blenlib/intern/BLI_ghash.c
===================================================================
diff --git a/source/blender/blenlib/intern/BLI_ghash.c b/source/blender/blenlib/intern/BLI_ghash.c
index 2819005..e9d0061 100644
--- a/source/blender/blenlib/intern/BLI_ghash.c
+++ b/source/blender/blenlib/intern/BLI_ghash.c
@@ -118,7 +118,7 @@ struct GHash {
BLI_INLINE void ghash_entry_copy(
GHash *gh_dst, Entry *dst, GHash *gh_src, Entry *src,
- const unsigned int UNUSED(hash), GHashKeyCopyFP keycopyfp, GHashValCopyFP valcopyfp)
+ GHashKeyCopyFP keycopyfp, GHashValCopyFP valcopyfp)
{
dst->key = (keycopyfp) ? keycopyfp(src->key) : src->key;
@@ -567,30 +567,30 @@ static GHash *ghash_copy(GHash *gh, GHashKeyCopyFP keycopyfp, GHashValCopyFP val
{
GHash *gh_new;
unsigned int i;
+ /* This allows us to be sure to get the same number of buckets in gh_new as in ghash. */
+ const unsigned int reserve_nentries_new = MAX2(GHASH_LIMIT_GROW(gh->nbuckets) - 1, gh->nentries);
BLI_assert(!valcopyfp || !(gh->flag & GHASH_FLAG_IS_GSET));
- gh_new = ghash_new(gh->hashfp, gh->cmpfp, __func__, 0, gh->flag & GHASH_FLAG_IS_GSET);
- ghash_buckets_expand(gh_new, gh->nentries, false);
+ gh_new = ghash_new(gh->hashfp, gh->cmpfp, __func__, 0, gh->flag);
+ ghash_buckets_expand(gh_new, reserve_nentries_new, false);
+
+ BLI_assert(gh_new->nbuckets == gh->nbuckets);
for (i = 0; i < gh->nbuckets; i++) {
Entry *e;
for (e = gh->buckets[i]; e; e = e->next) {
Entry *e_new = BLI_mempool_alloc(gh_new->entrypool);
- const unsigned int hash = ghash_entryhash(gh, e);
- const unsigned int gh_new_bucket_hash = ghash_bucket_hash(gh_new, hash);
-
- ghash_entry_copy(gh_new, e_new, gh, e, hash, keycopyfp, valcopyfp);
+ ghash_entry_copy(gh_new, e_new, gh, e, keycopyfp, valcopyfp);
/* Warning!
* This means entries in buckets in new copy will be in reversed order!
* This shall not be an issue though, since order should never be assumed in ghash. */
- /* Note: We can't use 'i' here, since there is no guaranty that 'gh' and 'gh_new'
- * have the same number of buckets! */
- e_new->next = gh_new->buckets[gh_new_bucket_hash];
- gh_new->buckets[gh_new_bucket_hash] = e_new;
+ /* Note: We can use 'i' here, since we are sure that 'gh' and 'gh_new' have the same number of buckets! */
+ e_new->next = gh_new->buckets[i];
+ gh_new->buckets[i] = e_new;
}
}
gh_new->nentries = gh->nentries;
More information about the Bf-blender-cvs
mailing list