Commit: e0f314d750fcafb00eb5ab5286ba89323f6f88cd
Author: Campbell Barton
Date:   Wed Jun 22 09:38:23 2016 +1000
Branches: master
https://developer.blender.org/rBe0f314d750fcafb00eb5ab5286ba89323f6f88cd

readfile: use BLI_endian_switch

Replace inline endian switching

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

M       source/blender/makesdna/intern/CMakeLists.txt
M       source/blender/makesdna/intern/dna_genfile.c

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

diff --git a/source/blender/makesdna/intern/CMakeLists.txt 
b/source/blender/makesdna/intern/CMakeLists.txt
index 52487ed..b4ada7f 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 b8783da..99ab29f 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));
                                }
                        }
                }

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to