[Bf-blender-cvs] [35b4e3a3501] master: RNA: Don't allocate empty char pointer properties

Hans Goudey noreply at git.blender.org
Tue Jul 19 17:29:34 CEST 2022


Commit: 35b4e3a3501c9c797f2269421bc778e949fb46af
Author: Hans Goudey
Date:   Tue Jul 19 10:30:10 2022 -0500
Branches: master
https://developer.blender.org/rB35b4e3a3501c9c797f2269421bc778e949fb46af

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

===================================================================

M	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. */



More information about the Bf-blender-cvs mailing list