[Bf-blender-cvs] [f181839] master: Cleanup: code-style

Campbell Barton noreply at git.blender.org
Tue Jun 28 12:29:42 CEST 2016


Commit: f181839c572fdffe9554cf7d9e41c7ceffeec02e
Author: Campbell Barton
Date:   Tue Jun 28 17:35:35 2016 +1000
Branches: master
https://developer.blender.org/rBf181839c572fdffe9554cf7d9e41c7ceffeec02e

Cleanup: code-style

Other changes here planned which touch many lines, so run cleanup first.

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

M	source/blender/blenloader/intern/writefile.c

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

diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 7a84eb6..5a7b2a7 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -173,7 +173,7 @@
 #include "BKE_mesh.h"
 
 #ifdef USE_NODE_COMPAT_CUSTOMNODES
-#include "NOD_socket.h"	/* for sock->default_value data */
+#include "NOD_socket.h"  /* for sock->default_value data */
 #endif
 
 
@@ -304,7 +304,7 @@ typedef struct {
 
 	unsigned char *buf;
 	MemFile *compare, *current;
-	
+
 	int tot, count, error;
 
 	/* Wrap writing, so we can use zlib or
@@ -319,21 +319,26 @@ typedef struct {
 
 static WriteData *writedata_new(WriteWrap *ww)
 {
-	WriteData *wd= MEM_callocN(sizeof(*wd), "writedata");
+	WriteData *wd = MEM_callocN(sizeof(*wd), "writedata");
 
 	wd->sdna = DNA_sdna_from_data(DNAstr, DNAlen, false);
 
 	wd->ww = ww;
 
-	wd->buf= MEM_mallocN(MYWRITE_BUFFER_SIZE, "wd->buf");
+	wd->buf = MEM_mallocN(MYWRITE_BUFFER_SIZE, "wd->buf");
 
 	return wd;
 }
 
 static void writedata_do_write(WriteData *wd, const void *mem, int memlen)
 {
-	if ((wd == NULL) || wd->error || (mem == NULL) || memlen < 1) return;
-	if (wd->error) return;
+	if ((wd == NULL) || wd->error || (mem == NULL) || memlen < 1) {
+		return;
+	}
+
+	if (UNLIKELY(wd->error)) {
+		return;
+	}
 
 	/* memory based save */
 	if (wd->current) {
@@ -367,29 +372,31 @@ static void writedata_free(WriteData *wd)
 
 static void mywrite(WriteData *wd, const void *adr, int len)
 {
-	if (wd->error) return;
+	if (UNLIKELY(wd->error)) {
+		return;
+	}
 
 	/* flush helps compression for undo-save */
-	if (adr==MYWRITE_FLUSH) {
+	if (adr == MYWRITE_FLUSH) {
 		if (wd->count) {
 			writedata_do_write(wd, wd->buf, wd->count);
-			wd->count= 0;
+			wd->count = 0;
 		}
 		return;
 	}
 
-	wd->tot+= len;
-	
+	wd->tot += len;
+
 	/* if we have a single big chunk, write existing data in
 	 * buffer and write out big chunk in smaller pieces */
-	if (len>MYWRITE_MAX_CHUNK) {
+	if (len > MYWRITE_MAX_CHUNK) {
 		if (wd->count) {
 			writedata_do_write(wd, wd->buf, wd->count);
-			wd->count= 0;
+			wd->count = 0;
 		}
 
 		do {
-			int writelen= MIN2(len, MYWRITE_MAX_CHUNK);
+			int writelen = MIN2(len, MYWRITE_MAX_CHUNK);
 			writedata_do_write(wd, adr, writelen);
 			adr = (const char *)adr + writelen;
 			len -= writelen;
@@ -399,14 +406,14 @@ static void mywrite(WriteData *wd, const void *adr, int len)
 	}
 
 	/* if data would overflow buffer, write out the buffer */
-	if (len+wd->count>MYWRITE_BUFFER_SIZE-1) {
+	if (len + wd->count > MYWRITE_BUFFER_SIZE - 1) {
 		writedata_do_write(wd, wd->buf, wd->count);
-		wd->count= 0;
+		wd->count = 0;
 	}
 
 	/* append data at end of buffer */
 	memcpy(&wd->buf[wd->count], adr, len);
-	wd->count+= len;
+	wd->count += len;
 }
 
 /**
@@ -418,15 +425,17 @@ static void mywrite(WriteData *wd, const void *adr, int len)
  */
 static WriteData *bgnwrite(WriteWrap *ww, MemFile *compare, MemFile *current)
 {
-	WriteData *wd= writedata_new(ww);
+	WriteData *wd = writedata_new(ww);
 
-	if (wd == NULL) return NULL;
+	if (wd == NULL) {
+		return NULL;
+	}
 
-	wd->compare= compare;
-	wd->current= current;
+	wd->compare = compare;
+	wd->current = current;
 	/* this inits comparing */
 	memfile_chunk_add(compare, NULL, NULL, 0);
-	
+
 	return wd;
 }
 
@@ -442,10 +451,10 @@ static int endwrite(WriteData *wd)
 
 	if (wd->count) {
 		writedata_do_write(wd, wd->buf, wd->count);
-		wd->count= 0;
+		wd->count = 0;
 	}
-	
-	err= wd->error;
+
+	err = wd->error;
 	writedata_free(wd);
 
 	return err;
@@ -460,23 +469,27 @@ static void writestruct_at_address(
 	BHead bh;
 	const short *sp;
 
-	if (adr==NULL || data==NULL || nr==0) return;
+	if (adr == NULL || data == NULL || nr == 0) {
+		return;
+	}
 
 	/* init BHead */
-	bh.code= filecode;
-	bh.old= adr;
-	bh.nr= nr;
+	bh.code = filecode;
+	bh.old = adr;
+	bh.nr = nr;
 
-	bh.SDNAnr= DNA_struct_find_nr(wd->sdna, structname);
-	if (bh.SDNAnr== -1) {
+	bh.SDNAnr = DNA_struct_find_nr(wd->sdna, structname);
+	if (bh.SDNAnr == -1) {
 		printf("error: can't find SDNA code <%s>\n", structname);
 		return;
 	}
-	sp= wd->sdna->structs[bh.SDNAnr];
+	sp = wd->sdna->structs[bh.SDNAnr];
 
-	bh.len= nr*wd->sdna->typelens[sp[0]];
+	bh.len = nr * wd->sdna->typelens[sp[0]];
 
-	if (bh.len==0) return;
+	if (bh.len == 0) {
+		return;
+	}
 
 	mywrite(wd, &bh, sizeof(BHead));
 	mywrite(wd, data, bh.len);
@@ -493,8 +506,9 @@ static void writedata(WriteData *wd, int filecode, int len, const void *adr)  /*
 {
 	BHead bh;
 
-	if (adr==NULL) return;
-	if (len==0) return;
+	if (adr == NULL || len == 0) {
+		return;
+	}
 
 	/* align to 4 (writes uninitialized bytes in some cases) */
 	len = (len + 3) & ~3;
@@ -514,7 +528,7 @@ static void writedata(WriteData *wd, int filecode, int len, const void *adr)  /*
 static void writelist(WriteData *wd, int filecode, const char *structname, const ListBase *lb)
 {
 	const Link *link = lb->first;
-	
+
 	while (link) {
 		writestruct(wd, filecode, structname, 1, link);
 		link = link->next;
@@ -533,11 +547,12 @@ static void IDP_WriteArray(const IDProperty *prop, void *wd)
 		writedata(wd, DATA, MEM_allocN_len(prop->data.pointer), prop->data.pointer);
 
 		if (prop->subtype == IDP_GROUP) {
-			IDProperty **array= prop->data.pointer;
+			IDProperty **array = prop->data.pointer;
 			int a;
 
-			for (a=0; a<prop->len; a++)
+			for (a = 0; a < prop->len; a++) {
 				IDP_WriteProperty(array[a], wd);
+			}
 		}
 	}
 }
@@ -551,8 +566,9 @@ static void IDP_WriteIDPArray(const IDProperty *prop, void *wd)
 
 		writestruct(wd, DATA, "IDProperty", prop->len, array);
 
-		for (a=0; a<prop->len; a++)
+		for (a = 0; a < prop->len; a++) {
 			IDP_WriteProperty_OnlyData(&array[a], wd);
+		}
 	}
 }
 
@@ -566,7 +582,7 @@ static void IDP_WriteGroup(const IDProperty *prop, void *wd)
 {
 	IDProperty *loop;
 
-	for (loop=prop->data.group.first; loop; loop=loop->next) {
+	for (loop = prop->data.group.first; loop; loop = loop->next) {
 		IDP_WriteProperty(loop, wd);
 	}
 }
@@ -629,45 +645,47 @@ static void write_previews(WriteData *wd, const PreviewImage *prv_orig)
 static void write_fmodifiers(WriteData *wd, ListBase *fmodifiers)
 {
 	FModifier *fcm;
-	
+
 	/* Write all modifiers first (for faster reloading) */
 	writelist(wd, DATA, "FModifier", fmodifiers);
-	
+
 	/* Modifiers */
-	for (fcm= fmodifiers->first; fcm; fcm= fcm->next) {
-		const FModifierTypeInfo *fmi= fmodifier_get_typeinfo(fcm);
-		
+	for (fcm = fmodifiers->first; fcm; fcm = fcm->next) {
+		const FModifierTypeInfo *fmi = fmodifier_get_typeinfo(fcm);
+
 		/* Write the specific data */
 		if (fmi && fcm->data) {
 			/* firstly, just write the plain fmi->data struct */
 			writestruct(wd, DATA, fmi->structName, 1, fcm->data);
-			
+
 			/* do any modifier specific stuff */
 			switch (fcm->type) {
 				case FMODIFIER_TYPE_GENERATOR:
 				{
-					FMod_Generator *data= (FMod_Generator *)fcm->data;
-					
+					FMod_Generator *data = fcm->data;
+
 					/* write coefficients array */
-					if (data->coefficients)
-						writedata(wd, DATA, sizeof(float)*(data->arraysize), data->coefficients);
+					if (data->coefficients) {
+						writedata(wd, DATA, sizeof(float) * (data->arraysize), data->coefficients);
+					}
 
 					break;
 				}
 				case FMODIFIER_TYPE_ENVELOPE:
 				{
-					FMod_Envelope *data= (FMod_Envelope *)fcm->data;
-					
+					FMod_Envelope *data = fcm->data;
+
 					/* write envelope data */
-					if (data->data)
+					if (data->data) {
 						writestruct(wd, DATA, "FCM_EnvelopeData", data->totvert, data->data);
+					}
 
 					break;
 				}
 				case FMODIFIER_TYPE_PYTHON:
 				{
-					FMod_Python *data = (FMod_Python *)fcm->data;
-					
+					FMod_Python *data = fcm->data;
+
 					/* Write ID Properties -- and copy this comment EXACTLY for easy finding
 					 * of library blocks that implement this.*/
 					IDP_WriteProperty(data->prop, wd);
@@ -682,37 +700,41 @@ static void write_fmodifiers(WriteData *wd, ListBase *fmodifiers)
 static void write_fcurves(WriteData *wd, ListBase *fcurves)
 {
 	FCurve *fcu;
-	
+
 	writelist(wd, DATA, "FCurve", fcurves);
-	for (fcu=fcurves->first; fcu; fcu=fcu->next) {
+	for (fcu = fcurves->first; fcu; fcu = fcu->next) {
 		/* curve data */
-		if (fcu->bezt)
+		if (fcu->bezt) {
 			writestruct(wd, DATA, "BezTriple", fcu->totvert, fcu->bezt);
-		if (fcu->fpt)
+		}
+		if (fcu->fpt) {
 			writestruct(wd, DATA, "FPoint", fcu->totvert, fcu->fpt);
-			
-		if (fcu->rna_path)
-			writedata(wd, DATA, strlen(fcu->rna_path)+1, fcu->rna_path);
-		
+		}
+
+		if (fcu->rna_path) {
+			writedata(wd, DATA, strlen(fcu->rna_path) + 1, fcu->rna_path);
+		}
+
 		/* driver data */
 		if (fcu->driver) {
-			ChannelDriver *driver= fcu->driver;
+			ChannelDriver *driver = fcu->driver;
 			DriverVar *dvar;
-			
+
 			writestruct(wd, DATA, "ChannelDriver", 1, driver);
-			
+
 			/* variables */
 			writelist(wd, DATA, "DriverVar", &driver->variables);
-			for (dvar= driver->variables.first; dvar; dvar= dvar->next) {				
+			for (dvar = driver->variables.first; dvar; dvar = dvar->next) {
 				DRIVER_TARGETS_USED_LOOPER(dvar)
 				{
-					if (dtar->rna_path)
-						writedata(wd, DATA, strlen(dtar->rna_path)+1, dtar->rna_path);
+					if (dtar->rna_path) {
+						writedata(wd, DATA, strlen(dtar->rna_path) + 1, dtar->rna_path);
+					}
 				}
 				DRIVER_TARGETS_LOOPER_END
 			}
 		}
-		
+
 		/* write F-Modifiers */
 		write_fmodifiers(wd, &fcu->modifiers);
 	}
@@ -720,27 +742,27 @@ static void write_fcurves(WriteData *wd, ListBase *fcurves)
 
 static void write_actions(WriteData *wd, ListBase *idbase)
 {
-	bAction	*act;
+	bAction *act;
 	bActionGroup *grp;
 	TimeMarker *marker;
-	
-	for (act=idbase->first; act; act= act->id.next) {
-		if (act->id.us>0 || wd->current) {
+
+	for (act = idbase->first; act; act = act->id.next) {
+		if (act->id.us > 0 || wd->current) {
 			writestruct(wd, ID_AC, "bAction", 1, act);
 			write_iddata(wd, &act->id);
 
 			write_fcurves(wd, &act->curves);
-			
-			for (grp=act->groups.first; grp; grp=grp->next) {
+
+			for (grp = act->groups.first; grp; grp = grp->next) {
 				writestruct(wd, DATA, "bActionGroup", 1, grp);
 			}
-			
-			for (marker=act->markers.first; marker; marker=marker->next) {
+


@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list