Skip to content

[DRAFT] Optimize Object::cast_to<T>() using Object::is_class() now that it takes a StringName#1974

Draft
dsnopek wants to merge 2 commits intogodotengine:masterfrom
dsnopek:better-object-cast-to
Draft

[DRAFT] Optimize Object::cast_to<T>() using Object::is_class() now that it takes a StringName#1974
dsnopek wants to merge 2 commits intogodotengine:masterfrom
dsnopek:better-object-cast-to

Conversation

@dsnopek
Copy link
Copy Markdown
Collaborator

@dsnopek dsnopek commented Apr 21, 2026

After godotengine/godot#118582, in Godot 4.7, Object::is_class() now takes a StringName which allows us to write a much simpler and faster version of Object::cast_to<T>() that doesn't use dynamic_cast<T>()

I've also chosen to simplify the code for Godot 4.6 and earlier to only do the dynamic_cast<T>(). Since we have to do that in the end anyway, we may as well skip all the other junk. This is theoretically slower if the object can't be cast to the requested type, but faster if it can, so I expect it to be a wash

This is marked as a DRAFT because it depends on #1972

@dsnopek dsnopek added this to the 10.x milestone Apr 21, 2026
@dsnopek dsnopek requested a review from Ivorforce April 21, 2026 19:30
@dsnopek dsnopek requested a review from a team as a code owner April 21, 2026 19:30
@dsnopek dsnopek added the enhancement This is an enhancement on the current functionality label Apr 21, 2026
@dsnopek dsnopek marked this pull request as draft April 21, 2026 19:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement This is an enhancement on the current functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant