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
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2021-08-17 17:22:23 +0300
committerCampbell Barton <ideasman42@gmail.com>2021-08-17 17:23:50 +0300
commit7f388725337d185a25b8dd3e90d479da86fb7aa1 (patch)
tree7ae2282ff2a8da81a468427d7db442edb7377136 /source/blender/makesrna/intern/makesrna.c
parent0246128b7f9c353641733f38dfafec362c3cf933 (diff)
RNA: de-duplicate enums in generated source
Reuse existing enums instead of expanding them since it bloats the binary. The icons enum for example contains over 900 items and was being expanded 17 times (once for each function that takes an icon argument). Similar with the event type enum which contains over 200 items and was duplicated 7 times. makesrna.c now matches enum definitions from declarations in RNA_enum_items.h, using their identifiers when found. The overall space saving on my system is 776kb (tested with a stripped release build). Reviewed By: brecht Ref D12245
Diffstat (limited to 'source/blender/makesrna/intern/makesrna.c')
-rw-r--r--source/blender/makesrna/intern/makesrna.c93
1 files changed, 67 insertions, 26 deletions
diff --git a/source/blender/makesrna/intern/makesrna.c b/source/blender/makesrna/intern/makesrna.c
index 719b0f73a9d..36f19907080 100644
--- a/source/blender/makesrna/intern/makesrna.c
+++ b/source/blender/makesrna/intern/makesrna.c
@@ -582,6 +582,23 @@ static int rna_color_quantize(PropertyRNA *prop, PropertyDefRNA *dp)
(IS_DNATYPE_FLOAT_COMPAT(dp->dnatype) == 0));
}
+/**
+ * Return the identifier for an enum which is defined in "RNA_enum_items.h".
+ *
+ * Prevents expanding duplicate enums bloating the binary size.
+ */
+static const char *rna_enum_id_from_pointer(const EnumPropertyItem *item)
+{
+#define RNA_MAKESRNA
+#define DEF_ENUM(id) \
+ if (item == id) { \
+ return STRINGIFY(id); \
+ }
+#include "RNA_enum_items.h"
+#undef RNA_MAKESRNA
+ return NULL;
+}
+
static const char *rna_function_string(const void *func)
{
return (func) ? (const char *)func : "NULL";
@@ -3675,37 +3692,55 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr
int i, defaultfound = 0, totflag = 0;
if (eprop->item) {
- fprintf(f,
- "static const EnumPropertyItem rna_%s%s_%s_items[%d] = {\n\t",
- srna->identifier,
- strnest,
- prop->identifier,
- eprop->totitem + 1);
-
- for (i = 0; i < eprop->totitem; i++) {
- fprintf(f, "{%d, ", eprop->item[i].value);
- rna_print_c_string(f, eprop->item[i].identifier);
- fprintf(f, ", ");
- fprintf(f, "%d, ", eprop->item[i].icon);
- rna_print_c_string(f, eprop->item[i].name);
- fprintf(f, ", ");
- rna_print_c_string(f, eprop->item[i].description);
- fprintf(f, "},\n\t");
-
- if (eprop->item[i].identifier[0]) {
- if (prop->flag & PROP_ENUM_FLAG) {
- totflag |= eprop->item[i].value;
+ /* Inline the enum if this is not a defined in "RNA_enum_items.h". */
+ const char *item_global_id = rna_enum_id_from_pointer(eprop->item);
+ if (item_global_id == NULL) {
+ fprintf(f,
+ "static const EnumPropertyItem rna_%s%s_%s_items[%d] = {\n\t",
+ srna->identifier,
+ strnest,
+ prop->identifier,
+ eprop->totitem + 1);
+
+ for (i = 0; i < eprop->totitem; i++) {
+ fprintf(f, "{%d, ", eprop->item[i].value);
+ rna_print_c_string(f, eprop->item[i].identifier);
+ fprintf(f, ", ");
+ fprintf(f, "%d, ", eprop->item[i].icon);
+ rna_print_c_string(f, eprop->item[i].name);
+ fprintf(f, ", ");
+ rna_print_c_string(f, eprop->item[i].description);
+ fprintf(f, "},\n\t");
+
+ if (eprop->item[i].identifier[0]) {
+ if (prop->flag & PROP_ENUM_FLAG) {
+ totflag |= eprop->item[i].value;
+ }
+ else {
+ if (eprop->defaultvalue == eprop->item[i].value) {
+ defaultfound = 1;
+ }
+ }
}
- else {
- if (eprop->defaultvalue == eprop->item[i].value) {
- defaultfound = 1;
+ }
+
+ fprintf(f, "{0, NULL, 0, NULL, NULL}\n};\n\n");
+ }
+ else {
+ for (i = 0; i < eprop->totitem; i++) {
+ if (eprop->item[i].identifier[0]) {
+ if (prop->flag & PROP_ENUM_FLAG) {
+ totflag |= eprop->item[i].value;
+ }
+ else {
+ if (eprop->defaultvalue == eprop->item[i].value) {
+ defaultfound = 1;
+ }
}
}
}
}
- fprintf(f, "{0, NULL, 0, NULL, NULL}\n};\n\n");
-
if (prop->flag & PROP_ENUM_FLAG) {
if (eprop->defaultvalue & ~totflag) {
CLOG_ERROR(&LOG,
@@ -4047,7 +4082,13 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr
rna_function_string(eprop->get_ex),
rna_function_string(eprop->set_ex));
if (eprop->item) {
- fprintf(f, "rna_%s%s_%s_items, ", srna->identifier, strnest, prop->identifier);
+ const char *item_global_id = rna_enum_id_from_pointer(eprop->item);
+ if (item_global_id != NULL) {
+ fprintf(f, "%s, ", item_global_id);
+ }
+ else {
+ fprintf(f, "rna_%s%s_%s_items, ", srna->identifier, strnest, prop->identifier);
+ }
}
else {
fprintf(f, "NULL, ");