[Bf-blender-cvs] [cc0cc880de5] master: Alembic: reduced code duplication in read_mcols()

Sybren A. Stüvel noreply at git.blender.org
Tue May 23 17:29:14 CEST 2017


Commit: cc0cc880de5a66d72f571bec4c7d3eb1219aefc0
Author: Sybren A. Stüvel
Date:   Tue May 23 14:19:38 2017 +0200
Branches: master
https://developer.blender.org/rBcc0cc880de5a66d72f571bec4c7d3eb1219aefc0

Alembic: reduced code duplication in read_mcols()

A big chunk of code was copied between the if and else bodies. By using
a boolean to store whether the c3f_ptr or c4f_ptr should be used, the
in-loop condition is kept as simple as possible.

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

M	source/blender/alembic/intern/abc_customdata.cc

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

diff --git a/source/blender/alembic/intern/abc_customdata.cc b/source/blender/alembic/intern/abc_customdata.cc
index 5fa3d10fa16..c42e5f808b5 100644
--- a/source/blender/alembic/intern/abc_customdata.cc
+++ b/source/blender/alembic/intern/abc_customdata.cc
@@ -228,38 +228,34 @@ using Alembic::AbcGeom::IC4fGeomParam;
 using Alembic::AbcGeom::IV2fGeomParam;
 
 static void read_mcols(const CDStreamConfig &config, void *data,
-                       const C3fArraySamplePtr &c3f_ptr, const C4fArraySamplePtr &c4f_ptr)
+                       const C3fArraySamplePtr &c3f_ptr,
+                       const C4fArraySamplePtr &c4f_ptr)
 {
 	MCol *cfaces = static_cast<MCol *>(data);
 	MPoly *polys = config.mpoly;
 	MLoop *mloops = config.mloop;
 
-	if (c3f_ptr) {
-		for (int i = 0; i < config.totpoly; ++i) {
-			MPoly *p = &polys[i];
-			MCol *cface = &cfaces[p->loopstart + p->totloop];
-			MLoop *mloop = &mloops[p->loopstart + p->totloop];
+	/* Either one or the other should be given. */
+	BLI_assert(c3f_ptr || c4f_ptr);
+	const bool use_c3f_ptr = (c3f_ptr.get() != nullptr);
 
-			for (int j = 0; j < p->totloop; ++j) {
-				cface--;
-				mloop--;
+	for (int i = 0; i < config.totpoly; ++i) {
+		MPoly *p = &polys[i];
+		MCol *cface = &cfaces[p->loopstart + p->totloop];
+		MLoop *mloop = &mloops[p->loopstart + p->totloop];
+
+		for (int j = 0; j < p->totloop; ++j) {
+			cface--;
+			mloop--;
+
+			if (use_c3f_ptr) {
 				const Imath::C3f &color = (*c3f_ptr)[mloop->v];
 				cface->a = FTOCHAR(color[0]);
 				cface->r = FTOCHAR(color[1]);
 				cface->g = FTOCHAR(color[2]);
 				cface->b = 255;
 			}
-		}
-	}
-	else if (c4f_ptr) {
-		for (int i = 0; i < config.totpoly; ++i) {
-			MPoly *p = &polys[i];
-			MCol *cface = &cfaces[p->loopstart + p->totloop];
-			MLoop *mloop = &mloops[p->loopstart + p->totloop];
-
-			for (int j = 0; j < p->totloop; ++j) {
-				cface--;
-				mloop--;
+			else {
 				const Imath::C4f &color = (*c4f_ptr)[mloop->v];
 				cface->a = FTOCHAR(color[0]);
 				cface->r = FTOCHAR(color[1]);




More information about the Bf-blender-cvs mailing list