[Bf-blender-cvs] [05f631b7ad6] blender-v2.93-release: Cleanup: use an intermediate value for cast_primitive_type
Campbell Barton
noreply at git.blender.org
Tue Feb 22 10:27:11 CET 2022
Commit: 05f631b7ad6c4f06defc0792bd7e59aad5def7ee
Author: Campbell Barton
Date: Tue Feb 8 11:50:14 2022 +1100
Branches: blender-v2.93-release
https://developer.blender.org/rB05f631b7ad6c4f06defc0792bd7e59aad5def7ee
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 6c88d5f7230..f7f3d8e0eb4 100644
--- a/source/blender/makesdna/intern/dna_genfile.c
+++ b/source/blender/makesdna/intern/dna_genfile.c
@@ -756,45 +756,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