Replace many uses of is_class with derives_from. (reverted)#110832
Replace many uses of is_class with derives_from. (reverted)#110832Repiteo merged 1 commit intogodotengine:masterfrom
is_class with derives_from. (reverted)#110832Conversation
2bd6e45 to
eb1b616
Compare
eb1b616 to
8ef4a43
Compare
|
Are there any implications for removing the GDExtension stuff? |
No. If we were checking for a GDExtension class with the call, it would not compile, because there would be no symbol for it. |
|
For the record, one use case for None of the replacements here seem to be that case though so it's fine. We'd usually favor |
I want to raise that Core classes checking for non-Core classes still breaks encapsulation. It just doesn't break it on an include level. It's still worth avoiding this situation, even with |
lawnjelly
left a comment
There was a problem hiding this comment.
Looks fine but I haven't tested, am assuming @Ivorforce has done some testing for regressions.
I ran the unit tests, but other than that, no. I don't expect any risks from this PR. The regex cases should be perfectly exchangeable. |
|
Thanks! |
|
|
||
| if (keep_transform) { | ||
| if (n2->is_class("Node3D")) { | ||
| if (n2->derives_from<Node3D>()) { |
There was a problem hiding this comment.
This, and probably many other cases, breaks 2D only builds, will make a report, but I think we should just roll this back and rework it as it's a serious breakage
Will test enclosing these cases in _3D_DISABLED and see that should fix it, but it makes it clear that this kind of change is a bit unstable
Some specific cases might still break in certain configurations if the relevant classes aren't available though
|
I'll just go ahead and make a revert PR for this for now, it's far too fragile to fix, we can retry this if it can be fixed properly later |
is_class with derives_from.is_class with derives_from. (reverted)
|
Did the usage of |
|
Yes, as a temporary measure. See #113152 |
AncestralClassto speed upObject::cast_towhen possible. #110763Object::is_classas a faster, static version ofobject->is_class#104992is_classby using static types instead of strings. #104924is_classis very slow: It necessitates allocating aString, and de-referencing many other strings to check against. This induces many RAM cache misses on cold access. It is also suboptimally implemented, making the same test several times in subclasses.In addition,
is_classcalls use string literals, which are error prone and don't support the "Go to" function of IDEs for quick navigation.Finally,
is_classuses odd type checking logic, which e.g. checksGDExtensiontypes but ignores scripting types, and will likely be phased out eventually.This PR uses the new
derives_fromfunction, which is at least several times faster thanis_class, in much of the codebase.I essentially used a regex replace (and deleted changes that led to compile errors, e.g. due to forward declarations):
This PR reduces the number of
is_classcalls within the engine by about 2/3.