Editmesh: Replace SmallHash with GSet for MESH_OT_loop_to_region
authorCampbell Barton <ideasman42@gmail.com>
Thu, 29 May 2014 04:03:22 +0000 (14:03 +1000)
committerCampbell Barton <ideasman42@gmail.com>
Fri, 13 Jun 2014 14:47:12 +0000 (00:47 +1000)
There no reason to assume hash will be small in this case

source/blender/editors/mesh/editmesh_select.c

index 467723e5e0a46ef654fbd39f98252a25d4397cc3..f58034c106699ba918b4f8fd482d22acc789aaf1 100644 (file)
@@ -3189,7 +3189,7 @@ void MESH_OT_region_to_loop(wmOperatorType *ot)
 }
 
 static int loop_find_region(BMLoop *l, int flag,
-                            SmallHash *fhash, BMFace ***region_out)
+                            GSet *visit_face_set, BMFace ***region_out)
 {
        BMFace **region = NULL;
        BMFace **stack = NULL;
@@ -3198,7 +3198,7 @@ static int loop_find_region(BMLoop *l, int flag,
        BMFace *f;
        
        BLI_array_append(stack, l->f);
-       BLI_smallhash_insert(fhash, (uintptr_t)l->f, NULL);
+       BLI_gset_insert(visit_face_set, l->f);
        
        while (BLI_array_count(stack) > 0) {
                BMIter liter1, liter2;
@@ -3217,11 +3217,10 @@ static int loop_find_region(BMLoop *l, int flag,
                                if (BM_elem_flag_test(l2->f, BM_ELEM_TAG)) {
                                        continue;
                                }
-                               if (BLI_smallhash_haskey(fhash, (uintptr_t)l2->f))
-                                       continue;
-                               
-                               BLI_array_append(stack, l2->f);
-                               BLI_smallhash_insert(fhash, (uintptr_t)l2->f, NULL);
+
+                               if (BLI_gset_add(visit_face_set, l2->f)) {
+                                       BLI_array_append(stack, l2->f);
+                               }
                        }
                }
        }
@@ -3254,13 +3253,13 @@ static int verg_radial(const void *va, const void *vb)
  */
 static int loop_find_regions(BMEditMesh *em, const bool selbigger)
 {
-       SmallHash visithash;
+       GSet *visit_face_set;
        BMIter iter;
        const int edges_len = em->bm->totedgesel;
        BMEdge *e, **edges;
        int count = 0, i;
        
-       BLI_smallhash_init_ex(&visithash, edges_len);
+       visit_face_set = BLI_gset_ptr_new_ex(__func__, edges_len);
        edges = MEM_mallocN(sizeof(*edges) * edges_len, __func__);
 
        i = 0;
@@ -3289,10 +3288,10 @@ static int loop_find_regions(BMEditMesh *em, const bool selbigger)
                        continue;
                
                BM_ITER_ELEM (l, &liter, e, BM_LOOPS_OF_EDGE) {
-                       if (BLI_smallhash_haskey(&visithash, (uintptr_t)l->f))
+                       if (BLI_gset_haskey(visit_face_set, l->f))
                                continue;
-                                               
-                       c = loop_find_region(l, BM_ELEM_SELECT, &visithash, &region_out);
+
+                       c = loop_find_region(l, BM_ELEM_SELECT, visit_face_set, &region_out);
 
                        if (!region || (selbigger ? c >= tot : c < tot)) {
                                /* this region is the best seen so far */
@@ -3327,7 +3326,7 @@ static int loop_find_regions(BMEditMesh *em, const bool selbigger)
        }
        
        MEM_freeN(edges);
-       BLI_smallhash_release(&visithash);
+       BLI_gset_free(visit_face_set, NULL);
        
        return count;
 }