1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-12 13:20:55 +00:00

Optimize Object::get_class_name

* Run the static function once per class instead of one per instance.
* Saves some memory in Object derived classes.
This commit is contained in:
Juan Linietsky
2023-04-07 23:32:37 +02:00
parent 61630d4e1e
commit 8950943356
4 changed files with 28 additions and 17 deletions

View File

@@ -195,14 +195,15 @@ bool Object::_predelete() {
_predelete_ok = 1;
notification(NOTIFICATION_PREDELETE, true);
if (_predelete_ok) {
_class_ptr = nullptr; //must restore so destructors can access class ptr correctly
_class_name_ptr = nullptr; // Must restore, so constructors/destructors have proper class name access at each stage.
}
return _predelete_ok;
}
void Object::_postinitialize() {
_class_ptr = _get_class_namev();
_class_name_ptr = _get_class_namev(); // Set the direct pointer, which is much faster to obtain, but can only happen after postinitialize.
_initialize_classv();
_class_name_ptr = nullptr; // May have been called from a constructor.
notification(NOTIFICATION_POSTINITIALIZE);
}