[Bf-blender-cvs] [0d444bd3efa] blenloader-api: simplify reading raw arrays of primitive types

Jacques Lucke noreply at git.blender.org
Sat Mar 7 19:09:27 CET 2020


Commit: 0d444bd3efa592d67ba3a319c27c25920bee6d26
Author: Jacques Lucke
Date:   Sat Mar 7 17:14:45 2020 +0100
Branches: blenloader-api
https://developer.blender.org/rB0d444bd3efa592d67ba3a319c27c25920bee6d26

simplify reading raw arrays of primitive types

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

M	source/blender/blenloader/BLO_callback_api.h
M	source/blender/modifiers/intern/MOD_hook.c

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

diff --git a/source/blender/blenloader/BLO_callback_api.h b/source/blender/blenloader/BLO_callback_api.h
index faae9e157b1..3d4d063e056 100644
--- a/source/blender/blenloader/BLO_callback_api.h
+++ b/source/blender/blenloader/BLO_callback_api.h
@@ -1,6 +1,8 @@
 #ifndef __BLO_CALLBACK_API_H__
 #define __BLO_CALLBACK_API_H__
 
+#include "BLI_endian_switch.h"
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -45,6 +47,15 @@ bool BLO_read_requires_endian_switch(BloReader *reader);
 typedef void (*BloLinkListFn)(BloReader *reader, void *data);
 void BLO_read_list(BloReader *reader, struct ListBase *list, BloLinkListFn callback);
 
+#define BLO_read_array_endian_corrected(reader, type_name, ptr, array_size) \
+  BLO_read_update_address(reader, ptr); \
+  if (BLO_read_requires_endian_switch(reader)) { \
+    BLI_endian_switch_##type_name##_array(ptr, array_size); \
+  }
+
+#define BLO_read_array_int32(reader, ptr, array_size) \
+  BLO_read_array_endian_corrected(reader, int32, ptr, array_size)
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/source/blender/modifiers/intern/MOD_hook.c b/source/blender/modifiers/intern/MOD_hook.c
index d90157e4b70..b155ccff776 100644
--- a/source/blender/modifiers/intern/MOD_hook.c
+++ b/source/blender/modifiers/intern/MOD_hook.c
@@ -138,11 +138,7 @@ static void bloWrite(BloWriter *writer, const ModifierData *md)
 static void bloRead(BloReader *reader, ModifierData *md)
 {
   HookModifierData *hmd = (HookModifierData *)md;
-
-  BLO_read_update_address(reader, hmd->indexar);
-  if (BLO_read_requires_endian_switch(reader)) {
-    BLI_endian_switch_int32_array(hmd->indexar, hmd->totindex);
-  }
+  BLO_read_array_int32(reader, hmd->indexar, hmd->totindex);
 
   BLO_read_update_address(reader, hmd->curfalloff);
   if (hmd->curfalloff) {



More information about the Bf-blender-cvs mailing list