Refactor: UI: Make uiItem
layout hierarchy use C++ inheritance.
#124405
No reviewers
Labels
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Code Documentation
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
FBX
Interest
Freestyle
Interest
Geometry Nodes
Interest
glTF
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Viewport & EEVEE
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Asset Browser Project
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Asset System
Module
Core
Module
Development Management
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Module
Viewport & EEVEE
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Severity
High
Severity
Low
Severity
Normal
Severity
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#124405
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "mont29/blender:tmp-ui-layout-cpp-allocation"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This commit turns the base struct
uiItem
and all of its descendants(including
uiButtonItem
, uiLayout`, etc.) into a C++ polymorphichierarchy of types.
This allows to use C++ type of memory management, and use non-trivial
types (which will be required to make
PointerRNA
non-trivial).It also moves the storage of these
uiItems
fromBLI_listbase
toblender::Vector
, as our C-based listbase implementation isincompatible with C++ polymorphism.
This also lead to making
uiItem
parameters of a few utils functionsconst
, to allow passing aroundblender::Span
instead of vectors tosome internal helpers.
uiItem
layout hierarchy use C++ inheritance.@blender-bot build
UI Layout: Refactor: Make `uiItem` layout hierarchy use C++ inheritance.to Refactor: UI: Make `uiItem` layout hierarchy use C++ inheritance.So much nicer! Thanks for doing this.
@ -146,3 +146,3 @@
bContextStore *context;
uiLayout *parent;
ListBase items;
blender::Vector<uiItem *> items;
A vector of
unique_ptr
would be even nicer I think. But okay to do that as a separate step.Can remove
// ListBase items;
though.Indeed moving to
unique_ptr
would be a good next step - but think this PR is changing more than enough already 😅@ -375,3 +366,3 @@
{
if (item->type == ITEM_BUTTON) {
uiButtonItem *bitem = (uiButtonItem *)item;
const uiButtonItem *bitem = dynamic_cast<const uiButtonItem *>(item);
dynamic_cast
is typically much slower thanreinterpret_cast
. 5-30 times slower according to https://stackoverflow.com/a/7579250/10444036Conceptually it's also redundant with the
item->type
check. If the item type doesn't match the actual type, we have much larger problems, sodynamic_cast
is not really making this safer. So I think it would be better to usereinterpret_cast
in this PR.I do not agree here... As pointed out in your stackoverflow thread, comparing
dynamic_cast
toreinterpret_cast
is useless, since the later usually does not do anything. In that sense,dynamic_cast
is infinitely slower thanreinterpret_cast
!And I think that the point of using C++ is also to have safer, saner, less heavy-maintenance code.
dynamic_cast
helps here, and can e.g. make catching invalid type casting caused by some random bug way easier.I don't see the point of sacrificing simplicity, maintainability, reliability and 'correctness' of code for nano-optimizations, unless there are evidences that the affected code is a bottleneck in performances.
dynamic_cast
is useful when you don't already store the type separately. It's redundant withitem->type
, so it's just misleading and wasteful.dynamic_cast
isn't simpler, and the only thing that's made "safer" is if the type is mismatched with the object type. That's not going to be a problem here.Not wasting time on small optimizations doesn't mean needlessly introducing overhead and redundancy. I would personally go with
std::variant
here overdynamic_cast
.@blender-bot build
So, talked to half a dozen devs in the team, and got about half recommending to use
dynamic_cast
, the other half recommending to usestatic_cast
.I would still rather stick to
dynamic_cast
personally, because the added cost is not an issue here, and it add some form of validation that the code handling theuiItem->type
data is not broken.But for the time being will switch the patch to
static_cast
, since this is essentially what the previous C code was doing.dynamic_cast
tostatic_cast
@blender-bot build
Thanks! Looks great to me now.