diff options
author | Campbell Barton <ideasman42@gmail.com> | 2018-12-02 00:13:31 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2018-12-02 02:15:22 +0300 |
commit | 8c620c8e2b3bf1f154f5d04e31e056bfc66d28df (patch) | |
tree | d28735e969c3fd7634d2e871b11dc4fcbd9ad259 /source/blender | |
parent | d3940c2211463609d4fa2b8601c64b3f7744a1f8 (diff) |
Optimize ghash usage
Avoid double hash calculation.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenkernel/intern/layer.c | 9 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/library_query.c | 6 |
2 files changed, 7 insertions, 8 deletions
diff --git a/source/blender/blenkernel/intern/layer.c b/source/blender/blenkernel/intern/layer.c index c591fa4bd80..1f2e54a6d39 100644 --- a/source/blender/blenkernel/intern/layer.c +++ b/source/blender/blenkernel/intern/layer.c @@ -681,12 +681,13 @@ static short layer_collection_sync( continue; } - Base *base = BLI_ghash_lookup(view_layer->object_bases_hash, cob->ob); - - if (base) { + void **base_p; + Base *base; + if (BLI_ghash_ensure_p(view_layer->object_bases_hash, cob->ob, &base_p)) { /* Move from old base list to new base list. Base might have already * been moved to the new base list and the first/last test ensure that * case also works. */ + base = *base_p; if (!ELEM(base, new_object_bases->first, new_object_bases->last)) { BLI_remlink(&view_layer->object_bases, base); BLI_addtail(new_object_bases, base); @@ -695,8 +696,8 @@ static short layer_collection_sync( else { /* Create new base. */ base = object_base_new(cob->ob); + *base_p = base; BLI_addtail(new_object_bases, base); - BLI_ghash_insert(view_layer->object_bases_hash, base->object, base); } int object_restrict = base->object->restrictflag; diff --git a/source/blender/blenkernel/intern/library_query.c b/source/blender/blenkernel/intern/library_query.c index f0f23eaa87d..6a9c1c82ab1 100644 --- a/source/blender/blenkernel/intern/library_query.c +++ b/source/blender/blenkernel/intern/library_query.c @@ -101,8 +101,7 @@ BLI_assert(*(id_pp) == old_id); \ } \ if (old_id && (_flag & IDWALK_RECURSE)) { \ - if (!BLI_gset_haskey((_data)->ids_handled, old_id)) { \ - BLI_gset_add((_data)->ids_handled, old_id); \ + if (BLI_gset_add((_data)->ids_handled, old_id)) { \ if (!(callback_return & IDWALK_RET_STOP_RECURSION)) { \ BLI_LINKSTACK_PUSH((_data)->ids_todo, old_id); \ } \ @@ -320,8 +319,7 @@ static void library_foreach_ID_as_subdata_link( if (flag & IDWALK_RECURSE) { /* Defer handling into main loop, recursively calling BKE_library_foreach_ID_link in IDWALK_RECURSE case is * troublesome, see T49553. */ - if (!BLI_gset_haskey(data->ids_handled, id)) { - BLI_gset_add(data->ids_handled, id); + if (BLI_gset_add(data->ids_handled, id)) { BLI_LINKSTACK_PUSH(data->ids_todo, id); } } |