[Bf-blender-cvs] [5bc2f90d6f2] soc-2017-normal-tools: Cleanup, remove dead code, do not allocate when not needed...

Bastien Montagne noreply at git.blender.org
Wed Feb 28 21:37:04 CET 2018


Commit: 5bc2f90d6f25feb8ba5998ff0c30a5bfef6aafb7
Author: Bastien Montagne
Date:   Wed Feb 28 16:44:19 2018 +0100
Branches: soc-2017-normal-tools
https://developer.blender.org/rB5bc2f90d6f25feb8ba5998ff0c30a5bfef6aafb7

Cleanup, remove dead code, do not allocate when not needed...

===================================================================

M	source/blender/bmesh/intern/bmesh_mesh.c
M	source/blender/bmesh/intern/bmesh_mesh.h

===================================================================

diff --git a/source/blender/bmesh/intern/bmesh_mesh.c b/source/blender/bmesh/intern/bmesh_mesh.c
index 5f3db67d850..8979fc0b089 100644
--- a/source/blender/bmesh/intern/bmesh_mesh.c
+++ b/source/blender/bmesh/intern/bmesh_mesh.c
@@ -1159,7 +1159,7 @@ void BM_lnorspace_rebuild(BMesh *bm, bool preserve_clnor)
 	BMIter fiter, liter;
 
 	float (*r_lnors)[3] = MEM_callocN(sizeof(*r_lnors) * bm->totloop, __func__);
-	float (*oldnors)[3] = MEM_mallocN(sizeof(*oldnors) * bm->totloop, __func__);
+	float (*oldnors)[3] = preserve_clnor ? MEM_mallocN(sizeof(*oldnors) * bm->totloop, __func__) : NULL;
 
 	int cd_loop_clnors_offset = CustomData_get_offset(&bm->ldata, CD_CUSTOMLOOPNORMAL);
 
@@ -1189,25 +1189,18 @@ void BM_lnorspace_rebuild(BMesh *bm, bool preserve_clnor)
 
 	BM_ITER_MESH(f, &fiter, bm, BM_FACES_OF_MESH) {
 		BM_ITER_ELEM(l, &liter, f, BM_LOOPS_OF_FACE) {
-
 			if (BM_ELEM_API_FLAG_TEST(l, BM_LNORSPACE_UPDATE) || bm->spacearr_dirty & BM_SPACEARR_DIRTY_ALL) {
-
-#if 0
-				short(*clnor)[2] = BM_ELEM_CD_GET_VOID_P(l, cd_loop_clnors_offset);
-				int l_index = BM_elem_index_get(l);
-				BKE_lnor_space_custom_normal_to_data(bm->lnor_spacearr->lspacearr[l_index], l->v->no, *clnor);
-#else
 				if (preserve_clnor) {
 					short(*clnor)[2] = BM_ELEM_CD_GET_VOID_P(l, cd_loop_clnors_offset);
 					int l_index = BM_elem_index_get(l);
 					BKE_lnor_space_custom_normal_to_data(bm->lnor_spacearr->lspacearr[l_index], oldnors[l_index], *clnor);
 				}
-#endif
 				BM_ELEM_API_FLAG_DISABLE(l, BM_LNORSPACE_UPDATE);
 			}
 		}
 	}
-	MEM_freeN(oldnors);
+
+	MEM_SAFE_FREE(oldnors);
 	bm->spacearr_dirty &= ~(BM_SPACEARR_DIRTY | BM_SPACEARR_DIRTY_ALL);
 
 #ifndef NDEBUG
@@ -1217,26 +1210,27 @@ void BM_lnorspace_rebuild(BMesh *bm, bool preserve_clnor)
 
 void BM_lnorspace_update(BMesh *bm)
 {
-	float (*lnors)[3] = MEM_callocN(sizeof(*lnors) * bm->totloop, __func__);
-
-	BM_mesh_elem_index_ensure(bm, BM_LOOP);
-
 	if (bm->lnor_spacearr == NULL) {
 		bm->lnor_spacearr = MEM_callocN(sizeof(*bm->lnor_spacearr), __func__);
 	}
 	if (bm->lnor_spacearr->lspacearr == NULL) {
+		float (*lnors)[3] = MEM_callocN(sizeof(*lnors) * bm->totloop, __func__);
+
 		BM_lnorspacearr_store(bm, lnors);
+
+		MEM_freeN(lnors);
 	}
 	else if(bm->spacearr_dirty & (BM_SPACEARR_DIRTY | BM_SPACEARR_DIRTY_ALL)){
 		BM_lnorspace_rebuild(bm, false);
 	}
-	MEM_freeN(lnors);
 }
 
 /**
- * Auxillary function only used by rebuild to detect if any spaces were not marked in invalidate.
- * Reports error if any of the lnor spaces change after rebuilding, meaning that the all possible
- * lnor spaces to be rebuilt were not correctly marked */
+ * Auxillary function only used by rebuild to detect if any spaces were not marked as invalid.
+ * Reports error if any of the lnor spaces change after rebuilding, meaning that all the possible
+ * lnor spaces to be rebuilt were not correctly marked.
+ */
+#ifndef NDEBUG
 void BM_lnorspace_err(BMesh *bm)
 {
 	bm->spacearr_dirty |= BM_SPACEARR_DIRTY_ALL;
@@ -1271,6 +1265,7 @@ void BM_lnorspace_err(BMesh *bm)
 
 	bm->spacearr_dirty &= ~BM_SPACEARR_DIRTY_ALL;
 }
+#endif
 
 /* Mark the individual clnors to be edited, if multiple selection methods are used. */
 static int bm_loop_normal_mark_indiv(BMesh *bm, BLI_bitmap *loops)
diff --git a/source/blender/bmesh/intern/bmesh_mesh.h b/source/blender/bmesh/intern/bmesh_mesh.h
index f9a89684aa7..487453815a4 100644
--- a/source/blender/bmesh/intern/bmesh_mesh.h
+++ b/source/blender/bmesh/intern/bmesh_mesh.h
@@ -58,7 +58,9 @@ void BM_lnorspacearr_store(BMesh *bm, float (*r_lnors)[3]);
 void BM_lnorspace_invalidate(BMesh *bm, const bool do_invalidate_all);
 void BM_lnorspace_rebuild(BMesh *bm, bool preserve_clnor);
 void BM_lnorspace_update(BMesh *bm);
+#ifndef NDEBUG
 void BM_lnorspace_err(BMesh *bm);
+#endif
 
 /* Loop Generics */
 LoopNormalData *BM_loop_normal_init(BMesh *bm);



More information about the Bf-blender-cvs mailing list