Cleanup: use enum constant for DNA comparison

This commit is contained in:
Campbell Barton 2016-01-16 15:00:22 +11:00
parent 63de1e7e7a
commit 92b222a158
4 changed files with 27 additions and 12 deletions

View File

@ -1847,11 +1847,12 @@ static void *read_struct(FileData *fd, BHead *bh, const char *blockname)
if (bh->SDNAnr && (fd->flags & FD_FLAGS_SWITCH_ENDIAN))
switch_endian_structs(fd->filesdna, bh);
if (fd->compflags[bh->SDNAnr]) { /* flag==0: doesn't exist anymore */
if (fd->compflags[bh->SDNAnr] == 2) {
if (fd->compflags[bh->SDNAnr] != SDNA_CMP_REMOVED) {
if (fd->compflags[bh->SDNAnr] == SDNA_CMP_NOT_EQUAL) {
temp = DNA_struct_reconstruct(fd->memsdna, fd->filesdna, fd->compflags, bh->SDNAnr, bh->nr, (bh+1));
}
else {
/* SDNA_CMP_EQUAL */
temp = MEM_mallocN(bh->len, blockname);
memcpy(temp, (bh+1), bh->len);
}

View File

@ -75,7 +75,7 @@ typedef struct FileData {
// general reading variables
struct SDNA *filesdna;
struct SDNA *memsdna;
char *compflags;
char *compflags; /* array of eSDNA_StructCompare */
int fileversion;
int id_name_offs; /* used to retrieve ID names from (bhead+1) */

View File

@ -65,6 +65,14 @@ typedef enum eSDNA_Type {
SDNA_TYPE_UINT64 = 11
} eSDNA_Type;
/**
* For use with #DNA_struct_reconstruct & #DNA_struct_get_compareflags
*/
enum eSDNA_StructCompare {
SDNA_CMP_REMOVED = 0,
SDNA_CMP_EQUAL = 1,
SDNA_CMP_NOT_EQUAL = 2,
};
struct SDNA *DNA_sdna_from_data(const void *data, const int datalen, bool do_endian_swap);
void DNA_sdna_free(struct SDNA *sdna);

View File

@ -582,7 +582,7 @@ static void recurs_test_compflags(const SDNA *sdna, char *compflags, int structn
typenr = sp[0];
for (a = 0; a < sdna->nr_structs; a++) {
if (a != structnr && compflags[a] == 1) {
if ((a != structnr) && (compflags[a] == SDNA_CMP_EQUAL)) {
sp = sdna->structs[a];
elems = sp[1];
sp += 2;
@ -590,7 +590,7 @@ static void recurs_test_compflags(const SDNA *sdna, char *compflags, int structn
if (sp[0] == typenr) {
cp = sdna->names[sp[1]];
if (!ispointer(cp)) {
compflags[a] = 2;
compflags[a] = SDNA_CMP_NOT_EQUAL;
recurs_test_compflags(sdna, compflags, a);
}
}
@ -635,7 +635,8 @@ char *DNA_struct_get_compareflags(SDNA *oldsdna, SDNA *newsdna)
sp_new = findstruct_name(newsdna, oldsdna->types[sp_old[0]]);
if (sp_new) {
compflags[a] = 2; /* initial assumption */
/* initial assumption */
compflags[a] = SDNA_CMP_NOT_EQUAL;
/* compare length and amount of elems */
if (sp_new[1] == sp_old[1]) {
@ -663,7 +664,10 @@ char *DNA_struct_get_compareflags(SDNA *oldsdna, SDNA *newsdna)
sp_old += 2;
sp_new += 2;
}
if (b == 0) compflags[a] = 1; /* no differences found */
if (b == 0) {
/* no differences found */
compflags[a] = SDNA_CMP_EQUAL;
}
}
}
@ -674,18 +678,20 @@ char *DNA_struct_get_compareflags(SDNA *oldsdna, SDNA *newsdna)
/* first struct in util.h is struct Link, this is skipped in compflags (als # 0).
* was a bug, and this way dirty patched! Solve this later....
*/
compflags[0] = 1;
compflags[0] = SDNA_CMP_EQUAL;
/* Because structs can be inside structs, we recursively
* set flags when a struct is altered
*/
for (a = 0; a < oldsdna->nr_structs; a++) {
if (compflags[a] == 2) recurs_test_compflags(oldsdna, compflags, a);
if (compflags[a] == SDNA_CMP_NOT_EQUAL) {
recurs_test_compflags(oldsdna, compflags, a);
}
}
#if 0
for (a = 0; a < oldsdna->nr_structs; a++) {
if (compflags[a] == 2) {
if (compflags[a] == SDNA_CMP_NOT_EQUAL) {
spold = oldsdna->structs[a];
printf("changed: %s\n", oldsdna->types[spold[0]]);
}
@ -1040,8 +1046,8 @@ static void reconstruct_struct(
if (oldSDNAnr == -1) return;
if (curSDNAnr == -1) return;
if (compflags[oldSDNAnr] == 1) { /* if recursive: test for equal */
if (compflags[oldSDNAnr] == SDNA_CMP_EQUAL) {
/* if recursive: test for equal */
spo = oldsdna->structs[oldSDNAnr];
elen = oldsdna->typelens[spo[0]];
memcpy(cur, data, elen);