diff options
author | Campbell Barton <ideasman42@gmail.com> | 2016-06-22 02:38:23 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2016-06-22 02:38:23 +0300 |
commit | e0f314d750fcafb00eb5ab5286ba89323f6f88cd (patch) | |
tree | f45db071b598fe50d64ea3ff6cd7f24651cde153 /source | |
parent | 68040359d1fe2e817c864393cf225a438f1fe1ab (diff) |
readfile: use BLI_endian_switch
Replace inline endian switching
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/makesdna/intern/CMakeLists.txt | 5 | ||||
-rw-r--r-- | source/blender/makesdna/intern/dna_genfile.c | 50 |
2 files changed, 10 insertions, 45 deletions
diff --git a/source/blender/makesdna/intern/CMakeLists.txt b/source/blender/makesdna/intern/CMakeLists.txt index 52487edfd2b..b4ada7ffbf1 100644 --- a/source/blender/makesdna/intern/CMakeLists.txt +++ b/source/blender/makesdna/intern/CMakeLists.txt @@ -94,10 +94,11 @@ set(INC_SYS ) set(SRC - ../../blenlib/intern/BLI_mempool.c - ../../blenlib/intern/listbase.c ../../blenlib/intern/BLI_ghash.c + ../../blenlib/intern/BLI_mempool.c + ../../blenlib/intern/endian_switch.c ../../blenlib/intern/hash_mm2a.c + ../../blenlib/intern/listbase.c ) blender_add_lib(bf_dna_blenlib "${SRC}" "${INC}" "${INC_SYS}") diff --git a/source/blender/makesdna/intern/dna_genfile.c b/source/blender/makesdna/intern/dna_genfile.c index b8783da73ca..99ab29fbdcc 100644 --- a/source/blender/makesdna/intern/dna_genfile.c +++ b/source/blender/makesdna/intern/dna_genfile.c @@ -43,6 +43,7 @@ #include "MEM_guardedalloc.h" // for MEM_freeN MEM_mallocN MEM_callocN #include "BLI_utildefines.h" +#include "BLI_endian_switch.h" #ifdef WITH_DNA_GHASH # include "BLI_ghash.h" @@ -1126,7 +1127,7 @@ void DNA_struct_switch_endian(SDNA *oldsdna, int oldSDNAnr, char *data) */ int a, mul, elemcount, elen, elena, firststructtypenr; const short *spo, *spc; - char *cpo, *cur, cval; + char *cur; const char *type, *name; if (oldSDNAnr == -1) return; @@ -1150,7 +1151,7 @@ void DNA_struct_switch_endian(SDNA *oldsdna, int oldSDNAnr, char *data) if (spc[0] >= firststructtypenr && !ispointer(name)) { /* struct field type */ /* where does the old data start (is there one?) */ - cpo = find_elem(oldsdna, type, name, spo, data, NULL); + char *cpo = find_elem(oldsdna, type, name, spo, data, NULL); if (cpo) { oldSDNAnr = DNA_struct_find_nr(oldsdna, type); @@ -1167,18 +1168,7 @@ void DNA_struct_switch_endian(SDNA *oldsdna, int oldSDNAnr, char *data) /* non-struct field type */ if (ispointer(name)) { if (oldsdna->pointerlen == 8) { - - mul = DNA_elem_array_size(name); - cpo = cur; - while (mul--) { - cval = cpo[0]; cpo[0] = cpo[7]; cpo[7] = cval; - cval = cpo[1]; cpo[1] = cpo[6]; cpo[6] = cval; - cval = cpo[2]; cpo[2] = cpo[5]; cpo[5] = cval; - cval = cpo[3]; cpo[3] = cpo[4]; cpo[4] = cval; - - cpo += 8; - } - + BLI_endian_switch_int64_array((int64_t *)cur, DNA_elem_array_size(name)); } } else { @@ -1191,14 +1181,7 @@ void DNA_struct_switch_endian(SDNA *oldsdna, int oldSDNAnr, char *data) } if (skip == false) { - mul = DNA_elem_array_size(name); - cpo = cur; - while (mul--) { - cval = cpo[0]; - cpo[0] = cpo[1]; - cpo[1] = cval; - cpo += 2; - } + BLI_endian_switch_int16_array((int16_t *)cur, DNA_elem_array_size(name)); } } else if (ELEM(spc[0], SDNA_TYPE_INT, SDNA_TYPE_FLOAT)) { @@ -1206,29 +1189,10 @@ void DNA_struct_switch_endian(SDNA *oldsdna, int oldSDNAnr, char *data) * but turns out we only used for runtime vars and * only once for a struct type thats no longer used. */ - mul = DNA_elem_array_size(name); - cpo = cur; - while (mul--) { - cval = cpo[0]; - cpo[0] = cpo[3]; - cpo[3] = cval; - cval = cpo[1]; - cpo[1] = cpo[2]; - cpo[2] = cval; - cpo += 4; - } + BLI_endian_switch_int32_array((int32_t *)cur, DNA_elem_array_size(name)); } else if (ELEM(spc[0], SDNA_TYPE_INT64, SDNA_TYPE_UINT64, SDNA_TYPE_DOUBLE)) { - mul = DNA_elem_array_size(name); - cpo = cur; - while (mul--) { - cval = cpo[0]; cpo[0] = cpo[7]; cpo[7] = cval; - cval = cpo[1]; cpo[1] = cpo[6]; cpo[6] = cval; - cval = cpo[2]; cpo[2] = cpo[5]; cpo[5] = cval; - cval = cpo[3]; cpo[3] = cpo[4]; cpo[4] = cval; - - cpo += 8; - } + BLI_endian_switch_int64_array((int64_t *)cur, DNA_elem_array_size(name)); } } } |