Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2015-04-06 13:03:49 +0300
committerCampbell Barton <ideasman42@gmail.com>2015-04-06 13:41:37 +0300
commit26e50295ceb81bd09f65d30116f897ba53e50daf (patch)
tree12a283bb2144b6f198f63de1429ae4f35d426a52
parentdd129125b6f6c9fff5ef4423b221cf68fedbd188 (diff)
Use BKE_ghash_ensure_p where possible
-rw-r--r--source/blender/blenkernel/intern/icons.c8
-rw-r--r--source/blender/blenkernel/intern/treehash.c10
-rw-r--r--source/blender/blenlib/intern/scanfill_utils.c10
-rw-r--r--source/blender/bmesh/intern/bmesh_log.c5
-rw-r--r--source/blender/bmesh/tools/bmesh_region_match.c25
-rw-r--r--source/blender/editors/transform/transform.c5
-rw-r--r--source/blender/modifiers/intern/MOD_build.c42
7 files changed, 62 insertions, 43 deletions
diff --git a/source/blender/blenkernel/intern/icons.c b/source/blender/blenkernel/intern/icons.c
index 8bda957f187..d3225f3fa35 100644
--- a/source/blender/blenkernel/intern/icons.c
+++ b/source/blender/blenkernel/intern/icons.c
@@ -311,16 +311,14 @@ Icon *BKE_icon_get(int icon_id)
void BKE_icon_set(int icon_id, struct Icon *icon)
{
- Icon *old_icon = NULL;
+ void **val_p;
- old_icon = BLI_ghash_lookup(gIcons, SET_INT_IN_POINTER(icon_id));
-
- if (old_icon) {
+ if (BLI_ghash_ensure_p(gIcons, SET_INT_IN_POINTER(icon_id), &val_p)) {
printf("BKE_icon_set: Internal error, icon already set: %d\n", icon_id);
return;
}
- BLI_ghash_insert(gIcons, SET_INT_IN_POINTER(icon_id), icon);
+ *val_p = icon;
}
void BKE_icon_delete(struct ID *id)
diff --git a/source/blender/blenkernel/intern/treehash.c b/source/blender/blenkernel/intern/treehash.c
index 866502c4ae1..43eeae7329e 100644
--- a/source/blender/blenkernel/intern/treehash.c
+++ b/source/blender/blenkernel/intern/treehash.c
@@ -129,11 +129,13 @@ void *BKE_treehash_rebuild_from_treestore(void *treehash, BLI_mempool *treestore
void BKE_treehash_add_element(void *treehash, TreeStoreElem *elem)
{
- TseGroup *group = BLI_ghash_lookup(treehash, elem);
- if (!group) {
- group = tse_group_create();
- BLI_ghash_insert(treehash, elem, group);
+ TseGroup *group;
+ void **val_p;
+
+ if (!BLI_ghash_ensure_p(treehash, elem, &val_p)) {
+ *val_p = tse_group_create();
}
+ group = *val_p;
tse_group_add(group, elem);
}
diff --git a/source/blender/blenlib/intern/scanfill_utils.c b/source/blender/blenlib/intern/scanfill_utils.c
index a606ac41aa1..d0420a30448 100644
--- a/source/blender/blenlib/intern/scanfill_utils.c
+++ b/source/blender/blenlib/intern/scanfill_utils.c
@@ -112,11 +112,13 @@ void BLI_scanfill_view3d_dump(ScanFillContext *sf_ctx)
static ListBase *edge_isect_ls_ensure(GHash *isect_hash, ScanFillEdge *eed)
{
ListBase *e_ls;
- e_ls = BLI_ghash_lookup(isect_hash, eed);
- if (e_ls == NULL) {
- e_ls = MEM_callocN(sizeof(ListBase), __func__);
- BLI_ghash_insert(isect_hash, eed, e_ls);
+ void **val_p;
+
+ if (!BLI_ghash_ensure_p(isect_hash, eed, &val_p)) {
+ *val_p = MEM_callocN(sizeof(ListBase), __func__);
}
+ e_ls = *val_p;
+
return e_ls;
}
diff --git a/source/blender/bmesh/intern/bmesh_log.c b/source/blender/bmesh/intern/bmesh_log.c
index 158c2aa4263..c53b7f939c9 100644
--- a/source/blender/bmesh/intern/bmesh_log.c
+++ b/source/blender/bmesh/intern/bmesh_log.c
@@ -836,14 +836,15 @@ void BM_log_vert_before_modified(BMLog *log, BMVert *v, const int cd_vert_mask_o
BMLogVert *lv;
unsigned int v_id = bm_log_vert_id_get(log, v);
void *key = SET_UINT_IN_POINTER(v_id);
+ void **val_p;
/* Find or create the BMLogVert entry */
if ((lv = BLI_ghash_lookup(entry->added_verts, key))) {
bm_log_vert_bmvert_copy(lv, v, cd_vert_mask_offset);
}
- else if (!BLI_ghash_haskey(entry->modified_verts, key)) {
+ else if (!BLI_ghash_ensure_p(entry->modified_verts, key, &val_p)) {
lv = bm_log_vert_alloc(log, v, cd_vert_mask_offset);
- BLI_ghash_insert(entry->modified_verts, key, lv);
+ *val_p = lv;
}
}
diff --git a/source/blender/bmesh/tools/bmesh_region_match.c b/source/blender/bmesh/tools/bmesh_region_match.c
index c695d4c1774..0c0bb892f7b 100644
--- a/source/blender/bmesh/tools/bmesh_region_match.c
+++ b/source/blender/bmesh/tools/bmesh_region_match.c
@@ -534,12 +534,13 @@ static void bm_uuidwalk_pass_add(
l_iter = l_first = BM_FACE_FIRST_LOOP(f);
do {
/* fill verts_new */
+ void **val_p;
if (!BLI_ghash_haskey(uuidwalk->verts_uuid, l_iter->v) &&
- !BLI_ghash_haskey(verts_uuid_pass, l_iter->v) &&
+ !BLI_ghash_ensure_p(verts_uuid_pass, l_iter->v, &val_p) &&
(bm_vert_is_uuid_connect(uuidwalk, l_iter->v) == true))
{
const UUID_Int uuid = bm_uuidwalk_calc_vert_uuid(uuidwalk, l_iter->v);
- BLI_ghash_insert(verts_uuid_pass, l_iter->v, (void *)uuid);
+ *val_p = (void *)uuid;
}
/* fill faces_step_next */
@@ -667,13 +668,15 @@ static bool bm_uuidwalk_facestep_begin(
if (!BLI_ghash_haskey(uuidwalk->faces_uuid, f)) {
const UUID_Int uuid = bm_uuidwalk_calc_face_uuid(uuidwalk, f);
UUIDFaceStepItem *fstep_item;
+ void **val_p;
ok = true;
- fstep_item = BLI_ghash_lookup(uuidwalk->cache.faces_from_uuid, (void *)uuid);
- if (UNLIKELY(fstep_item == NULL)) {
- fstep_item = BLI_mempool_alloc(uuidwalk->step_pool_items);
- BLI_ghash_insert(uuidwalk->cache.faces_from_uuid, (void *)uuid, fstep_item);
+ if (BLI_ghash_ensure_p(uuidwalk->cache.faces_from_uuid, (void *)uuid, &val_p)) {
+ fstep_item = *val_p;
+ }
+ else {
+ fstep_item = *val_p = BLI_mempool_alloc(uuidwalk->step_pool_items);
/* add to start, so its handled on the next round of passes */
BLI_addhead(&fstep->items, fstep_item);
@@ -1111,9 +1114,10 @@ static BMEdge *bm_face_region_pivot_edge_find(
if (bm_edge_is_region_boundary(e)) {
unsigned int j;
for (j = 0; j < 2; j++) {
- if (!BLI_ghash_haskey(gh, (&e->v1)[j])) {
+ void **val_p;
+ if (!BLI_ghash_ensure_p(gh, (&e->v1)[j], &val_p)) {
SUID_Int v_id = bm_face_region_vert_boundary_id((&e->v1)[j]);
- BLI_ghash_insert(gh, (&e->v1)[j], (void *)v_id);
+ *val_p = (void *)v_id;
BLI_LINKSTACK_PUSH(vert_queue_prev, (&e->v1)[j]);
vert_queue_used += 1;
}
@@ -1137,10 +1141,11 @@ static BMEdge *bm_face_region_pivot_edge_find(
if (BM_elem_flag_test(e, BM_ELEM_TAG)) {
BMVert *v_other = BM_edge_other_vert(e, v);
if (BM_elem_flag_test(v_other, BM_ELEM_TAG)) {
- if (!BLI_ghash_haskey(gh, v_other)) {
+ void **val_p;
+ if (!BLI_ghash_ensure_p(gh, v_other, &val_p)) {
/* add as negative, so we know not to read from them this pass */
const SUID_Int v_id_other = -bm_face_region_vert_pass_id(gh, v_other);
- BLI_ghash_insert(gh, v_other, (void *)v_id_other);
+ *val_p = (void *)v_id_other;
BLI_LINKSTACK_PUSH(vert_queue_next, v_other);
vert_queue_used += 1;
}
diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c
index 401accba40b..161b8ca232d 100644
--- a/source/blender/editors/transform/transform.c
+++ b/source/blender/editors/transform/transform.c
@@ -5266,9 +5266,10 @@ static void slide_origdata_create_data_vert(
loop_weights = BLI_array_alloca(loop_weights, l_num);
for (j = 0; j < l_num; j++) {
BMLoop *l = BM_iter_step(&liter);
- if (!BLI_ghash_haskey(sod->origfaces, l->f)) {
+ void **val_p;
+ if (!BLI_ghash_ensure_p(sod->origfaces, l->f, &val_p)) {
BMFace *f_copy = BM_face_copy(sod->bm_origfaces, bm, l->f, true, true);
- BLI_ghash_insert(sod->origfaces, l->f, f_copy);
+ *val_p = f_copy;
}
loop_weights[j] = BM_loop_calc_face_angle(l);
}
diff --git a/source/blender/modifiers/intern/MOD_build.c b/source/blender/modifiers/intern/MOD_build.c
index 1dc1a1f8d64..96337c33373 100644
--- a/source/blender/modifiers/intern/MOD_build.c
+++ b/source/blender/modifiers/intern/MOD_build.c
@@ -131,6 +131,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *UNUSED(ob),
MPoly *mpoly, *mp;
MLoop *ml, *mloop;
MEdge *medge;
+ uintptr_t hash_num, hash_num_alt;
if (bmd->flag & MOD_BUILD_FLAG_RANDOMIZE) {
BLI_array_randomize(faceMap, sizeof(*faceMap),
@@ -142,40 +143,44 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *UNUSED(ob),
*/
mpoly = mpoly_src;
mloop = mloop_src;
+ hash_num = 0;
for (i = 0; i < numFaces_dst; i++) {
mp = mpoly + faceMap[i];
ml = mloop + mp->loopstart;
for (j = 0; j < mp->totloop; j++, ml++) {
- if (!BLI_ghash_haskey(vertHash, SET_INT_IN_POINTER(ml->v)))
- BLI_ghash_insert(vertHash, SET_INT_IN_POINTER(ml->v),
- SET_INT_IN_POINTER(BLI_ghash_size(vertHash)));
+ void **val_p;
+ if (!BLI_ghash_ensure_p(vertHash, SET_INT_IN_POINTER(ml->v), &val_p)) {
+ *val_p = (void *)hash_num;
+ hash_num++;
+ }
}
-
+
numLoops_dst += mp->totloop;
}
+ BLI_assert(hash_num == BLI_ghash_size(vertHash));
/* get the set of edges that will be in the new mesh (i.e. all edges
* that have both verts in the new mesh)
*/
medge = medge_src;
- for (i = 0; i < numEdge_src; i++) {
+ hash_num = 0;
+ hash_num_alt = 0;
+ for (i = 0; i < numEdge_src; i++, hash_num_alt++) {
MEdge *me = medge + i;
if (BLI_ghash_haskey(vertHash, SET_INT_IN_POINTER(me->v1)) &&
BLI_ghash_haskey(vertHash, SET_INT_IN_POINTER(me->v2)))
{
- j = BLI_ghash_size(edgeHash);
-
- BLI_ghash_insert(edgeHash, SET_INT_IN_POINTER(j),
- SET_INT_IN_POINTER(i));
- BLI_ghash_insert(edgeHash2, SET_INT_IN_POINTER(i),
- SET_INT_IN_POINTER(j));
+ BLI_ghash_insert(edgeHash, (void *)hash_num, (void *)hash_num_alt);
+ BLI_ghash_insert(edgeHash2, (void *)hash_num_alt, (void *)hash_num);
+ hash_num++;
}
}
}
else if (numEdges_dst) {
MEdge *medge, *me;
+ uintptr_t hash_num;
if (bmd->flag & MOD_BUILD_FLAG_RANDOMIZE)
BLI_array_randomize(edgeMap, sizeof(*edgeMap),
@@ -185,17 +190,22 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *UNUSED(ob),
* mapped to the new indices
*/
medge = medge_src;
+ hash_num = 0;
+ BLI_assert(hash_num == BLI_ghash_size(vertHash));
for (i = 0; i < numEdges_dst; i++) {
+ void **val_p;
me = medge + edgeMap[i];
- if (!BLI_ghash_haskey(vertHash, SET_INT_IN_POINTER(me->v1))) {
- BLI_ghash_insert(vertHash, SET_INT_IN_POINTER(me->v1),
- SET_INT_IN_POINTER(BLI_ghash_size(vertHash)));
+ if (!BLI_ghash_ensure_p(vertHash, SET_INT_IN_POINTER(me->v1), &val_p)) {
+ *val_p = (void *)hash_num;
+ hash_num++;
}
- if (!BLI_ghash_haskey(vertHash, SET_INT_IN_POINTER(me->v2))) {
- BLI_ghash_insert(vertHash, SET_INT_IN_POINTER(me->v2), SET_INT_IN_POINTER(BLI_ghash_size(vertHash)));
+ if (!BLI_ghash_ensure_p(vertHash, SET_INT_IN_POINTER(me->v2), &val_p)) {
+ *val_p = (void *)hash_num;
+ hash_num++;
}
}
+ BLI_assert(hash_num == BLI_ghash_size(vertHash));
/* get the set of edges that will be in the new mesh */
for (i = 0; i < numEdges_dst; i++) {