Exchange use of ClassDB::is_parent_class() with Object::is_class() where possible#118575
Exchange use of ClassDB::is_parent_class() with Object::is_class() where possible#118575DeeJayLSP wants to merge 1 commit intogodotengine:masterfrom
ClassDB::is_parent_class() with Object::is_class() where possible#118575Conversation
1cd656f to
aa86599
Compare
GDType for hierarchy instead of ClassDB where possibleObject for hierarchy instead of ClassDB where possible
aa86599 to
fc30511
Compare
Object for hierarchy instead of ClassDB where possibleGDType for hierarchy instead of ClassDB where possible
fc30511 to
4769777
Compare
GDType for hierarchy instead of ClassDB where possibleClassDB::is_parent_class() with Object::is_type() where possible
|
@Ivorforce this may be a reasonable follow-up of #118582 |
ClassDB::is_parent_class() with Object::is_type() where possibleClassDB::is_parent_class() with Object::is_class() where possible
| } | ||
| } | ||
| const bool is_script = ClassDB::is_parent_class(p_resource->get_class(), "Script"); | ||
| const bool is_script = p_resource->is_class("Script"); |
There was a problem hiding this comment.
Could we get an existing StringName rather than parsing a char *? For example:
| const bool is_script = p_resource->is_class("Script"); | |
| const bool is_script = p_resource->is_class(Script::get_class_static()); |
There was a problem hiding this comment.
The point of is_class() is to avoid including the class.
And if the class is already included, it's better to use Object::cast_to<>() or derives_from(). Using is_class() with get_class_static() does not make much sense.
Though for static strings, you can use SNAME at least.
There was a problem hiding this comment.
StringName lookup by key is about 3x faster than String allocation for the same key (i tested this once). ClassDB's lock + has lookup makes it even worse. So while using SNAME would be even faster, most (90+%?) of the performance gap is already addressed in this PR, even without SNAME use.
…` where possible
4769777 to
d376b20
Compare
|
Applied the |
Replaces instances of
ClassDB::is_parent_class()where you have access to the object itself, like:With:
object->is_class(inherits);Functionally identical, except we skip
ClassDB's lookup by name and directly check using the object's ownGDType.Hierarchy is constructed alongside the
GDTypeitself (not during initialization) and tests pass, so I assume this is a safe change.