Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2015-03-13 15:48:45 +0300
committerCampbell Barton <ideasman42@gmail.com>2015-03-13 15:52:47 +0300
commitfc3de690ac0603b566998b8a68b3c38d7767c9b6 (patch)
tree69acb9c8691387ad98fbff6730ee68f508655ee6 /source
parenta1a7317f6b098ab6928f33754e57de219877cb64 (diff)
RNA: avoid inefficient array printing
Diffstat (limited to 'source')
-rw-r--r--source/blender/makesrna/intern/rna_access.c28
1 files changed, 24 insertions, 4 deletions
diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c
index c3499d0b139..2a0fd14e13b 100644
--- a/source/blender/makesrna/intern/rna_access.c
+++ b/source/blender/makesrna/intern/rna_access.c
@@ -5462,14 +5462,20 @@ char *RNA_property_as_string(bContext *C, PointerRNA *ptr, PropertyRNA *prop, in
BLI_dynstr_append(dynstr, bool_as_py_string(RNA_property_boolean_get_index(ptr, prop, index)));
}
else {
+ int fixedbuf[RNA_MAX_ARRAY_LENGTH];
+ int *buf = ARRAY_SIZE(fixedbuf) >= len ? fixedbuf : MEM_mallocN(sizeof(*buf) * len, __func__);
+
+ RNA_property_boolean_get_array(ptr, prop, buf);
BLI_dynstr_append(dynstr, "(");
for (i = 0; i < len; i++) {
- BLI_dynstr_appendf(dynstr, i ? ", %s" : "%s",
- bool_as_py_string(RNA_property_boolean_get_index(ptr, prop, i)));
+ BLI_dynstr_appendf(dynstr, i ? ", %s" : "%s", bool_as_py_string(buf[i]));
}
if (len == 1)
BLI_dynstr_append(dynstr, ","); /* otherwise python wont see it as a tuple */
BLI_dynstr_append(dynstr, ")");
+ if (buf != fixedbuf) {
+ MEM_freeN(buf);
+ }
}
}
break;
@@ -5482,13 +5488,20 @@ char *RNA_property_as_string(bContext *C, PointerRNA *ptr, PropertyRNA *prop, in
BLI_dynstr_appendf(dynstr, "%d", RNA_property_int_get_index(ptr, prop, index));
}
else {
+ int fixedbuf[RNA_MAX_ARRAY_LENGTH];
+ int *buf = ARRAY_SIZE(fixedbuf) >= len ? fixedbuf : MEM_mallocN(sizeof(*buf) * len, __func__);
+
+ RNA_property_int_get_array(ptr, prop, buf);
BLI_dynstr_append(dynstr, "(");
for (i = 0; i < len; i++) {
- BLI_dynstr_appendf(dynstr, i ? ", %d" : "%d", RNA_property_int_get_index(ptr, prop, i));
+ BLI_dynstr_appendf(dynstr, i ? ", %d" : "%d", buf[i]);
}
if (len == 1)
BLI_dynstr_append(dynstr, ","); /* otherwise python wont see it as a tuple */
BLI_dynstr_append(dynstr, ")");
+ if (buf != fixedbuf) {
+ MEM_freeN(buf);
+ }
}
}
break;
@@ -5501,13 +5514,20 @@ char *RNA_property_as_string(bContext *C, PointerRNA *ptr, PropertyRNA *prop, in
BLI_dynstr_appendf(dynstr, "%g", RNA_property_float_get_index(ptr, prop, index));
}
else {
+ float fixedbuf[RNA_MAX_ARRAY_LENGTH];
+ float *buf = ARRAY_SIZE(fixedbuf) >= len ? fixedbuf : MEM_mallocN(sizeof(*buf) * len, __func__);
+
+ RNA_property_float_get_array(ptr, prop, buf);
BLI_dynstr_append(dynstr, "(");
for (i = 0; i < len; i++) {
- BLI_dynstr_appendf(dynstr, i ? ", %g" : "%g", RNA_property_float_get_index(ptr, prop, i));
+ BLI_dynstr_appendf(dynstr, i ? ", %g" : "%g", buf[i]);
}
if (len == 1)
BLI_dynstr_append(dynstr, ","); /* otherwise python wont see it as a tuple */
BLI_dynstr_append(dynstr, ")");
+ if (buf != fixedbuf) {
+ MEM_freeN(buf);
+ }
}
}
break;