[Bf-blender-cvs] [7df651367fb] master: Cleanup: use an intermediate value for cast_primitive_type
Campbell Barton
noreply at git.blender.org
Tue Feb 8 01:55:08 CET 2022
Commit: 7df651367fbd8c9510c7e02b18301bd2f28c3574
Author: Campbell Barton
Date: Tue Feb 8 11:50:14 2022 +1100
Branches: master
https://developer.blender.org/rB7df651367fbd8c9510c7e02b18301bd2f28c3574
Cleanup: use an intermediate value for cast_primitive_type
Assign the actual value before casting to large uint64_t/double types.
This improves readability, especially in cases where both pointer
and integer casts were used in one expression, to make matters worse
clang-format treated these casts as a multiplication.
This also made debugging/printing the values more of a hassle.
No functional changes (GCC produced identical output).
===================================================================
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 6322cb459dd..7e9fabcc998 100644
--- a/source/blender/makesdna/intern/dna_genfile.c
+++ b/source/blender/makesdna/intern/dna_genfile.c
@@ -737,45 +737,65 @@ static void cast_primitive_type(const eSDNA_Type old_type,
for (int a = 0; a < array_len; a++) {
switch (old_type) {
- case SDNA_TYPE_CHAR:
- old_value_i = *old_data;
+ case SDNA_TYPE_CHAR: {
+ const char value = *old_data;
+ old_value_i = value;
old_value_f = (double)old_value_i;
break;
- case SDNA_TYPE_UCHAR:
- old_value_i = *((unsigned char *)old_data);
+ }
+ case SDNA_TYPE_UCHAR: {
+ const uchar value = *((uchar *)old_data);
+ old_value_i = value;
old_value_f = (double)old_value_i;
break;
- case SDNA_TYPE_SHORT:
- old_value_i = *((short *)old_data);
+ }
+ case SDNA_TYPE_SHORT: {
+ const short value = *((short *)old_data);
+ old_value_i = value;
old_value_f = (double)old_value_i;
break;
- case SDNA_TYPE_USHORT:
- old_value_i = *((unsigned short *)old_data);
+ }
+ case SDNA_TYPE_USHORT: {
+ const ushort value = *((unsigned short *)old_data);
+ old_value_i = value;
old_value_f = (double)old_value_i;
break;
- case SDNA_TYPE_INT:
- old_value_i = *((int *)old_data);
+ }
+ case SDNA_TYPE_INT: {
+ const int value = *((int *)old_data);
+ old_value_i = value;
old_value_f = (double)old_value_i;
break;
- case SDNA_TYPE_FLOAT:
- old_value_f = *((float *)old_data);
+ }
+ case SDNA_TYPE_FLOAT: {
+ const float value = *((float *)old_data);
+ old_value_f = value;
old_value_i = (uint64_t)(int64_t)old_value_f;
break;
- case SDNA_TYPE_DOUBLE:
- old_value_f = *((double *)old_data);
+ }
+ case SDNA_TYPE_DOUBLE: {
+ const double value = *((double *)old_data);
+ old_value_f = value;
old_value_i = (uint64_t)(int64_t)old_value_f;
break;
- case SDNA_TYPE_INT64:
- old_value_i = (uint64_t) * ((int64_t *)old_data);
+ }
+ case SDNA_TYPE_INT64: {
+ const int64_t value = *((int64_t *)old_data);
+ old_value_i = (uint64_t)value;
old_value_f = (double)old_value_i;
break;
- case SDNA_TYPE_UINT64:
- old_value_i = *((uint64_t *)old_data);
+ }
+ case SDNA_TYPE_UINT64: {
+ const uint64_t value = *((uint64_t *)old_data);
+ old_value_i = value;
old_value_f = (double)old_value_i;
break;
- case SDNA_TYPE_INT8:
- old_value_i = (uint64_t) * ((int8_t *)old_data);
+ }
+ case SDNA_TYPE_INT8: {
+ const int8_t value = *((int8_t *)old_data);
+ old_value_i = (uint64_t)value;
old_value_f = (double)old_value_i;
+ }
}
switch (new_type) {
More information about the Bf-blender-cvs
mailing list