diff options
author | Bastien Montagne <bastien@blender.org> | 2022-05-17 16:11:57 +0300 |
---|---|---|
committer | Bastien Montagne <bastien@blender.org> | 2022-05-17 17:06:54 +0300 |
commit | 9a4cb7a7320c8b550d8fda0b47a559b850ed5e05 (patch) | |
tree | 1e504ed15d050b376d1b97dc1236319150f7ab6a /source/blender/makesrna/intern/rna_access.c | |
parent | 6d42cd8ff9da5b0a264c2950e8ddaa8d5ca9dc8b (diff) |
Cleanup: Use `switch` and `BLI_assert_unreachable()` more.
Replace some `if/else if` chains by proper `switch` statement.
Replace some `BLI_assert(0)` calls by `BLI_assert_unreachable()` ones.
Diffstat (limited to 'source/blender/makesrna/intern/rna_access.c')
-rw-r--r-- | source/blender/makesrna/intern/rna_access.c | 82 |
1 files changed, 45 insertions, 37 deletions
diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c index 8f7660d4015..53fa7a3d923 100644 --- a/source/blender/makesrna/intern/rna_access.c +++ b/source/blender/makesrna/intern/rna_access.c @@ -6723,23 +6723,27 @@ static void *rna_array_as_string_alloc( int type, int len, PointerRNA *ptr, PropertyRNA *prop, void **r_buf_end) { void *buf_ret = NULL; - if (type == PROP_BOOLEAN) { - bool *buf = buf_ret = MEM_mallocN(sizeof(*buf) * len, __func__); - RNA_property_boolean_get_array(ptr, prop, buf); - *r_buf_end = buf + len; - } - else if (type == PROP_INT) { - int *buf = buf_ret = MEM_mallocN(sizeof(*buf) * len, __func__); - RNA_property_int_get_array(ptr, prop, buf); - *r_buf_end = buf + len; - } - else if (type == PROP_FLOAT) { - float *buf = buf_ret = MEM_mallocN(sizeof(*buf) * len, __func__); - RNA_property_float_get_array(ptr, prop, buf); - *r_buf_end = buf + len; - } - else { - BLI_assert(0); + switch (type) { + case PROP_BOOLEAN: { + bool *buf = buf_ret = MEM_mallocN(sizeof(*buf) * len, __func__); + RNA_property_boolean_get_array(ptr, prop, buf); + *r_buf_end = buf + len; + break; + } + case PROP_INT: { + int *buf = buf_ret = MEM_mallocN(sizeof(*buf) * len, __func__); + RNA_property_int_get_array(ptr, prop, buf); + *r_buf_end = buf + len; + break; + } + case PROP_FLOAT: { + float *buf = buf_ret = MEM_mallocN(sizeof(*buf) * len, __func__); + RNA_property_float_get_array(ptr, prop, buf); + *r_buf_end = buf + len; + break; + } + default: + BLI_assert_unreachable(); } return buf_ret; } @@ -6749,29 +6753,33 @@ static void rna_array_as_string_elem(int type, void **buf_p, int len, DynStr *dy /* This will print a comma separated string of the array elements from * buf start to len. We will add a comma if len == 1 to preserve tuples. */ const int end = len - 1; - if (type == PROP_BOOLEAN) { - bool *buf = *buf_p; - for (int i = 0; i < len; i++, buf++) { - BLI_dynstr_appendf(dynstr, (i < end || !end) ? "%s, " : "%s", bool_as_py_string(*buf)); + switch (type) { + case PROP_BOOLEAN: { + bool *buf = *buf_p; + for (int i = 0; i < len; i++, buf++) { + BLI_dynstr_appendf(dynstr, (i < end || !end) ? "%s, " : "%s", bool_as_py_string(*buf)); + } + *buf_p = buf; + break; } - *buf_p = buf; - } - else if (type == PROP_INT) { - int *buf = *buf_p; - for (int i = 0; i < len; i++, buf++) { - BLI_dynstr_appendf(dynstr, (i < end || !end) ? "%d, " : "%d", *buf); + case PROP_INT: { + int *buf = *buf_p; + for (int i = 0; i < len; i++, buf++) { + BLI_dynstr_appendf(dynstr, (i < end || !end) ? "%d, " : "%d", *buf); + } + *buf_p = buf; + break; } - *buf_p = buf; - } - else if (type == PROP_FLOAT) { - float *buf = *buf_p; - for (int i = 0; i < len; i++, buf++) { - BLI_dynstr_appendf(dynstr, (i < end || !end) ? "%g, " : "%g", *buf); + case PROP_FLOAT: { + float *buf = *buf_p; + for (int i = 0; i < len; i++, buf++) { + BLI_dynstr_appendf(dynstr, (i < end || !end) ? "%g, " : "%g", *buf); + } + *buf_p = buf; + break; } - *buf_p = buf; - } - else { - BLI_assert(0); + default: + BLI_assert_unreachable(); } } |