From 58c460b3b7a644388e7eaaa0e513ed509634c844 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20T=2E=20Listwon?= Date: Sat, 8 Jan 2022 14:02:43 +0100 Subject: [PATCH] Removed redundant ClassDB::is_class_enabled() and moved second dynamic_cast inside worst case if (cherry picked from commit b6cfc55113609155ecbd5ada410c184776abadee) --- scene/resources/packed_scene.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/scene/resources/packed_scene.cpp b/scene/resources/packed_scene.cpp index 01e5cce4df6..c86a78698d7 100644 --- a/scene/resources/packed_scene.cpp +++ b/scene/resources/packed_scene.cpp @@ -175,14 +175,12 @@ Node *SceneState::instance(GenEditState p_edit_state) const { #endif } } else { - Object *obj = nullptr; + //node belongs to this scene and must be created + Object *obj = ClassDB::instance(snames[n.type]); - if (ClassDB::is_class_enabled(snames[n.type])) { - //node belongs to this scene and must be created - obj = ClassDB::instance(snames[n.type]); - } + node = Object::cast_to(obj); - if (!Object::cast_to(obj)) { + if (!node) { if (obj) { memdelete(obj); obj = nullptr; @@ -201,9 +199,9 @@ Node *SceneState::instance(GenEditState p_edit_state) const { if (!obj) { obj = memnew(Node); } - } - node = Object::cast_to(obj); + node = Object::cast_to(obj); + } } if (node) {