Page MenuHome

RNA: Don't allocate empty char pointer properties
ClosedPublic

Authored by Hans Goudey (HooglyBoogly) on Apr 27 2022, 4:59 PM.

Details

Summary

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.


There are 43 total char * members in DNA*types.h files (including const char *). Here I'll categorize them:

  • Affected by change (Exposed to RNA with no custom get and set), null checks everywhere: SpreadsheetRowFilter::value_string, NodeInputString::string, bNodeSocket::default_attribute_name, Curves::surface_uv_map
  • Affected by change (Exposed to RNA with no custom get and set), null checks in most places: SpreadsheetContextNode::node_name, SpreadsheetContextModifier::modifier_name, SpreadsheetColumnID::name
  • Exposed to RNA with custom get and set, does use null: TextLine::format, NodeCryptomatte::matte_id, ShaderNodeScript::bytecode, TexPaintSlot::uvname, Curve::str, AssetMetaData::author, AssetMetaData::description, KS_Path::rna_path, FCurve::rna_path, DriverTarget::rna_path
  • Exposed to RNA with custom get and set, does not use null: Text::filepath, TextLine::line, ConsoleLine::line
  • Exposed to RNA with custom get, no set: FileDirEntry::relpath, FileDirEntry::name, TexPaintSlot::attribute_name
  • Not exposed to RNA, runtime data: WorkSpace::status_text, Report::typestr, Report::message, FileDirEntry::redirection_path, ShaderFxData::error, ARegion::headerstr, SpreadsheetColumn::display_name, ARegion_Runtime::category, ModifierData::error, GpencilModifierData::error, AnimOverride::rna_path
  • Not exposed to RNA, other: RE_engine_id_BLENDER_EEVEE, RE_engine_id_BLENDER_WORKBENCH, RE_engine_id_CYCLES, SDNA::data, PointCache::cached_frames, Object::matbits, LightCacheTexture::data
  • Totally unused: uiList::custom_drag_opname, uiList::custom_activate_opname

Diff Detail

Repository
rB Blender

Event Timeline

Hans Goudey (HooglyBoogly) requested review of this revision.Apr 27 2022, 4:59 PM
Hans Goudey (HooglyBoogly) created this revision.
Hans Goudey (HooglyBoogly) edited the summary of this revision. (Show Details)

Can you make a quick list of the dna members that could be affected by this change?

There are 43 total char * members in DNA*types.h files (including const char *). Here I'll categorize them:

  • Affected by change (Exposed to RNA with no custom get and set), null checks everywhere: SpreadsheetRowFilter::value_string, NodeInputString::string, bNodeSocket::default_attribute_name, Curves::surface_uv_map
  • Affected by change (Exposed to RNA with no custom get and set), null checks in most places: SpreadsheetContextNode::node_name, SpreadsheetContextModifier::modifier_name, SpreadsheetColumnID::name
  • Exposed to RNA with custom get and set, does use null: TextLine::format, NodeCryptomatte::matte_id, ShaderNodeScript::bytecode, TexPaintSlot:;uvname, Curve::str, AssetMetaData::author, AssetMetaData::description, KS_Path::rna_path, FCurve::rna_path, DriverTarget::rna_path
  • Exposed to RNA with custom get and set, does not use null: Text::filepath, TextLine::line, ConsoleLine::line
  • Exposed to RNA with custom get, no set: FileDirEntry::relpath, FileDirEntry::name, TexPaintSlot::attribute_name
  • Not exposed to RNA, runtime data: WorkSpace::status_text, Report::typestr, Report::message, FileDirEntry::redirection_path, ShaderFxData::error, ARegion::headerstr, SpreadsheetColumn::display_name, ARegion_Runtime::category, ModifierData::error, GpencilModifierData::error, AnimOverride::rna_path
  • Not exposed to RNA, other: RE_engine_id_BLENDER_EEVEE, RE_engine_id_BLENDER_WORKBENCH, RE_engine_id_CYCLES, SDNA::data, PointCache::cached_frames, Object::matbits, LightCacheTexture::data
  • Totally unused: uiList::custom_drag_opname, uiList::custom_activate_opname

That was interesting! This is good because the only areas that are affects are code that we're responsible for already. The change looks safe to me.
Many of the items in the "Exposed to RNA with custom get and set, does use null" list could be simplified to avoid defining RNA getters and setters manually after this. I'll leave that for another time though.

This revision is now accepted and ready to land.Jul 19 2022, 3:00 PM