[Bf-blender-cvs] [82bd1287dd0] master: Cleanup: reduce variable scope
Jacques Lucke
noreply at git.blender.org
Thu Sep 17 14:20:36 CEST 2020
Commit: 82bd1287dd046650ff223edd0d54c43814945dc1
Author: Jacques Lucke
Date: Thu Sep 17 14:10:32 2020 +0200
Branches: master
https://developer.blender.org/rB82bd1287dd046650ff223edd0d54c43814945dc1
Cleanup: reduce variable scope
===================================================================
M source/blender/makesdna/intern/dna_genfile.c
===================================================================
diff --git a/source/blender/makesdna/intern/dna_genfile.c b/source/blender/makesdna/intern/dna_genfile.c
index b9688df8a3e..77f27223722 100644
--- a/source/blender/makesdna/intern/dna_genfile.c
+++ b/source/blender/makesdna/intern/dna_genfile.c
@@ -186,9 +186,8 @@ static bool ispointer(const char *name)
*/
int DNA_elem_size_nr(const SDNA *sdna, short type, short name)
{
- int len;
const char *cp = sdna->names[name];
- len = 0;
+ int len = 0;
/* is it a pointer or function pointer? */
if (ispointer(cp)) {
@@ -334,10 +333,9 @@ BLI_INLINE const char *pad_up_4(const char *ptr)
*/
static bool init_structDNA(SDNA *sdna, bool do_endian_swap, const char **r_error_message)
{
- int *data, gravity_fix = -1;
- short *sp;
+ int gravity_fix = -1;
- data = (int *)sdna->data;
+ int *data = (int *)sdna->data;
/* Clear pointers in case of error. */
sdna->names = NULL;
@@ -431,6 +429,7 @@ static bool init_structDNA(SDNA *sdna, bool do_endian_swap, const char **r_error
/* Type lengths array ('TLEN') */
data = (int *)cp;
+ short *sp;
if (*data == MAKE_ID('T', 'L', 'E', 'N')) {
data++;
sp = (short *)data;
@@ -623,22 +622,18 @@ void DNA_sdna_current_free(void)
*/
static void recurs_test_compflags(const SDNA *sdna, char *compflags, int structnr)
{
- int a, b, typenr, elems;
- const short *sp;
- const char *cp;
-
/* check all structs, test if it's inside another struct */
- sp = sdna->structs[structnr];
- typenr = sp[0];
+ const short *sp = sdna->structs[structnr];
+ const int typenr = sp[0];
- for (a = 0; a < sdna->structs_len; a++) {
+ for (int a = 0; a < sdna->structs_len; a++) {
if ((a != structnr) && (compflags[a] == SDNA_CMP_EQUAL)) {
sp = sdna->structs[a];
- elems = sp[1];
+ const int elems = sp[1];
sp += 2;
- for (b = 0; b < elems; b++, sp += 2) {
+ for (int b = 0; b < elems; b++, sp += 2) {
if (sp[0] == typenr) {
- cp = sdna->names[sp[1]];
+ const char *cp = sdna->names[sp[1]];
if (!ispointer(cp)) {
compflags[a] = SDNA_CMP_NOT_EQUAL;
recurs_test_compflags(sdna, compflags, a);
@@ -655,25 +650,20 @@ static void recurs_test_compflags(const SDNA *sdna, char *compflags, int structn
*/
const char *DNA_struct_get_compareflags(const SDNA *oldsdna, const SDNA *newsdna)
{
- int a, b;
- const short *sp_old, *sp_new;
- const char *str1, *str2;
- char *compflags;
-
if (oldsdna->structs_len == 0) {
printf("error: file without SDNA\n");
return NULL;
}
- compflags = MEM_callocN(oldsdna->structs_len, "compflags");
+ char *compflags = MEM_callocN(oldsdna->structs_len, "compflags");
/* we check all structs in 'oldsdna' and compare them with
* the structs in 'newsdna'
*/
unsigned int newsdna_index_last = 0;
- for (a = 0; a < oldsdna->structs_len; a++) {
- sp_old = oldsdna->structs[a];
+ for (int a = 0; a < oldsdna->structs_len; a++) {
+ const short *sp_old = oldsdna->structs[a];
/* search for type in cur */
int sp_new_index = DNA_struct_find_nr_ex(
@@ -683,7 +673,7 @@ const char *DNA_struct_get_compareflags(const SDNA *oldsdna, const SDNA *newsdna
newsdna_index_last++;
if (sp_new_index != -1) {
- sp_new = newsdna->structs[sp_new_index];
+ const short *sp_new = newsdna->structs[sp_new_index];
/* initial assumption */
compflags[a] = SDNA_CMP_NOT_EQUAL;
@@ -692,12 +682,12 @@ const char *DNA_struct_get_compareflags(const SDNA *oldsdna, const SDNA *newsdna
if (newsdna->types_size[sp_new[0]] == oldsdna->types_size[sp_old[0]]) {
/* same length, same amount of elems, now per type and name */
- b = sp_old[1];
+ int b = sp_old[1];
sp_old += 2;
sp_new += 2;
while (b > 0) {
- str1 = newsdna->types[sp_new[0]];
- str2 = oldsdna->types[sp_old[0]];
+ const char *str1 = newsdna->types[sp_new[0]];
+ const char *str2 = oldsdna->types[sp_old[0]];
if (!STREQ(str1, str2)) {
break;
}
@@ -736,7 +726,7 @@ const char *DNA_struct_get_compareflags(const SDNA *oldsdna, const SDNA *newsdna
/* Because structs can be inside structs, we recursively
* set flags when a struct is altered
*/
- for (a = 0; a < oldsdna->structs_len; a++) {
+ for (int a = 0; a < oldsdna->structs_len; a++) {
if (compflags[a] == SDNA_CMP_NOT_EQUAL) {
recurs_test_compflags(oldsdna, compflags, a);
}
@@ -913,15 +903,13 @@ static void cast_elem(
static void cast_pointer(
int curlen, int oldlen, int name_array_len, char *curdata, const char *olddata)
{
- int64_t lval;
-
while (name_array_len > 0) {
if (curlen == oldlen) {
memcpy(curdata, olddata, curlen);
}
else if (curlen == 4 && oldlen == 8) {
- lval = *((int64_t *)olddata);
+ int64_t lval = *((int64_t *)olddata);
/* WARNING: 32-bit Blender trying to load file saved by 64-bit Blender,
* pointers may lose uniqueness on truncation! (Hopefully this wont
@@ -982,15 +970,12 @@ static bool elem_exists_impl(
const char *name,
const short *old)
{
- int a, elemcount;
- const char *otype, *oname;
-
/* in old is the old struct */
- elemcount = old[1];
+ const int elemcount = old[1];
old += 2;
- for (a = 0; a < elemcount; a++, old += 2) {
- otype = types[old[0]];
- oname = names[old[1]];
+ for (int a = 0; a < elemcount; a++, old += 2) {
+ const char *otype = types[old[0]];
+ const char *oname = names[old[1]];
if (elem_streq(name, oname)) { /* name equal */
return STREQ(type, otype); /* type equal */
@@ -1053,20 +1038,17 @@ static const char *find_elem(const SDNA *sdna,
const char *olddata,
const short **sppo)
{
- int a, elemcount, len;
- const char *otype, *oname;
-
/* without arraypart, so names can differ: return old namenr and type */
/* in old is the old struct */
- elemcount = old[1];
+ const int elemcount = old[1];
old += 2;
- for (a = 0; a < elemcount; a++, old += 2) {
+ for (int a = 0; a < elemcount; a++, old += 2) {
- otype = sdna->types[old[0]];
- oname = sdna->names[old[1]];
+ const char *otype = sdna->types[old[0]];
+ const char *oname = sdna->names[old[1]];
- len = DNA_elem_size_nr(sdna, old[0], old[1]);
+ const int len = DNA_elem_size_nr(sdna, old[0], old[1]);
if (elem_streq(name, oname)) { /* name equal */
if (STREQ(type, otype)) { /* type equal */
@@ -1113,13 +1095,11 @@ static void reconstruct_elem(const SDNA *newsdna,
* (nzc 2-4-2001 I want the 'unsigned' bit to be parsed as well. Where
* can I force this?)
*/
- int a, elemcount, len, countpos, mul;
- const char *otype, *oname, *cp;
/* is 'name' an array? */
const char *name = newsdna->names[new_name_nr];
- cp = name;
- countpos = 0;
+ const char *cp = name;
+ int countpos = 0;
while (*cp && *cp != '[') {
cp++;
countpos++;
@@ -1129,13 +1109,13 @@ static void reconstruct_elem(const SDNA *newsdna,
}
/* in old is the old struct */
- elemcount = old[1];
+ const int elemcount = old[1];
old += 2;
- for (a = 0; a < elemcount; a++, old += 2) {
+ for (int a = 0; a < elemcount; a++, old += 2) {
const int old_name_nr = old[1];
- otype = oldsdna->types[old[0]];
- oname = oldsdna->names[old[1]];
- len = DNA_elem_size_nr(oldsdna, old[0], old[1]);
+ const char *otype = oldsdna->types[old[0]];
+ const char *oname = oldsdna->names[old[1]];
+ const int len = DNA_elem_size_nr(oldsdna, old[0], old[1]);
if (STREQ(name, oname)) { /* name equal */
@@ -1167,8 +1147,8 @@ static void reconstruct_elem(const SDNA *newsdna,
newsdna->pointer_size, oldsdna->pointer_size, min_name_array_len, curdata, olddata);
}
else if (STREQ(type, otype)) { /* type equal */
- /* size of single old array element */
- mul = len / old_name_array_len;
+ /* size of single old array element */
+ int mul = len / old_name_array_len;
/* smaller of sizes of old and new arrays */
mul *= min_name_array_len;
@@ -1215,15 +1195,6 @@ static void reconstruct_struct(const SDNA *newsdna,
* Per element from cur_struct, read data from old_struct.
* If element is a struct, call recursive.
*/
- int a, elemcount, elen, eleno, mul, mulo, firststructtypenr;
- const short *spo, *spc, *sppo;
- const char *type;
- const char *cpo;
- char *cpc;
- const char *name;
-
- unsigned int oldsdna_index_last = UINT_MAX;
- unsigned int cursdna_index_last = UINT_MAX;
if (oldSDNAnr == -1) {
return;
@@ -1234,27 +1205,27 @@ static void reconstruct_struct(const SDNA *newsdna,
if (compflags[oldSDNAnr] == SDNA_CMP_EQUAL) {
/* if recursive: test for equal */
- spo = oldsdna->structs[oldSDNAnr];
- elen = oldsdna->types_size[spo[0]];
+ const short *spo = oldsdna->structs[oldSDNAnr];
+ const int elen = oldsdna->types_size[spo[0]];
memcpy(cur, data, elen);
return;
}
- firststructtypenr = *(newsdna->structs[0]);
+ const int firststructtypenr = *(newsdna->structs[0]);
- spo = oldsdna->structs[oldSDNAnr];
- spc = newsdna->structs[curSDNAnr];
+ const short *spo = oldsdna->structs[oldSDNAnr];
+ const short *spc = newsdna->structs[curSDNAnr];
- elemcount = spc[1];
+ const int elemcount = spc[1];
spc += 2;
- cpc = cur;
- for (a = 0; a < elemcount; a++, spc += 2) { /* convert each field */
- type = newsdna->types[spc[0]];
- name = newsdna->names[spc[1]];
+ char *cpc = cur;
+ for (int a = 0; a < elemcount; a++, spc += 2) { /* convert each field */
+ const char *type = newsdna->types[spc[0]];
+ const char *name = newsdna->names[spc[1]];
- elen = DNA_elem_size_nr(newsdna, spc[0], spc[1]);
+ int elen = DNA_elem_size_nr(newsdna, spc[0], spc[1]);
/* Skip pad bytes which must start with '_pad', see makesdna.c 'is_name_legal'.
* for exact rules. Note that if we fail to skip a pad byte it's harmless,
@@ -1266,17 +1237,20 @@ static void
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list