From 35b4e3a3501c9c797f2269421bc778e949fb46af Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Tue, 19 Jul 2022 10:30:10 -0500 Subject: RNA: Don't allocate empty char pointer properties Instead of allocating a single 0 char, set the `char *` DNA pointer to null. This avoids the overhead of allocating and copying single-bytes. rBeed45b655c9f didn't do this for safety reasons, but I checked the existing uses of this behavior in DNA/RNA. Out of 43 total `char *` members, this change only affects 7 recently added properties. For a complete list, see the patch description. Differential Revision: https://developer.blender.org/D14779 --- source/blender/makesrna/intern/makesrna.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'source/blender/makesrna/intern/makesrna.c') diff --git a/source/blender/makesrna/intern/makesrna.c b/source/blender/makesrna/intern/makesrna.c index b5354514205..a25fe201fa2 100644 --- a/source/blender/makesrna/intern/makesrna.c +++ b/source/blender/makesrna/intern/makesrna.c @@ -1117,8 +1117,10 @@ static char *rna_def_property_set_func( fprintf( f, " if (data->%s != NULL) { MEM_freeN(data->%s); }\n", dp->dnaname, dp->dnaname); fprintf(f, " const int length = strlen(value);\n"); - fprintf(f, " data->%s = MEM_mallocN(length + 1, __func__);\n", dp->dnaname); - fprintf(f, " %s(data->%s, value, length + 1);\n", string_copy_func, dp->dnaname); + fprintf(f, " if (length > 0) {\n"); + fprintf(f, " data->%s = MEM_mallocN(length + 1, __func__);\n", dp->dnaname); + fprintf(f, " %s(data->%s, value, length + 1);\n", string_copy_func, dp->dnaname); + fprintf(f, " } else { data->%s = NULL; }\n", dp->dnaname); } else { /* Handle char array properties. */ -- cgit v1.2.3