Skip to content

Commit 4b36c04

Browse files
committed
Merge pull request #105020 from YYF233333/opt_get_inheriters
Optimize `ClassDB::get_inheriters_from_class`
2 parents f4c7a5a + 4029051 commit 4b36c04

12 files changed

+23
-23
lines changed

core/core_bind.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,8 +1437,8 @@ PackedStringArray ClassDB::get_class_list() const {
14371437
}
14381438

14391439
PackedStringArray ClassDB::get_inheriters_from_class(const StringName &p_class) const {
1440-
List<StringName> classes;
1441-
::ClassDB::get_inheriters_from_class(p_class, &classes);
1440+
LocalVector<StringName> classes;
1441+
::ClassDB::get_inheriters_from_class(p_class, classes);
14421442

14431443
PackedStringArray ret;
14441444
ret.resize(classes.size());

core/object/class_db.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,12 +281,12 @@ void ClassDB::get_extension_class_list(const Ref<GDExtension> &p_extension, List
281281
}
282282
#endif
283283

284-
void ClassDB::get_inheriters_from_class(const StringName &p_class, List<StringName> *p_classes) {
284+
void ClassDB::get_inheriters_from_class(const StringName &p_class, LocalVector<StringName> &p_classes) {
285285
Locker::Lock lock(Locker::STATE_READ);
286286

287287
for (const KeyValue<StringName, ClassInfo> &E : classes) {
288288
if (E.key != p_class && _is_parent_class(E.key, p_class)) {
289-
p_classes->push_back(E.key);
289+
p_classes.push_back(E.key);
290290
}
291291
}
292292
}

core/object/class_db.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ class ClassDB {
311311
static void get_extension_class_list(const Ref<GDExtension> &p_extension, List<StringName> *p_classes);
312312
static ObjectGDExtension *get_placeholder_extension(const StringName &p_class);
313313
#endif
314-
static void get_inheriters_from_class(const StringName &p_class, List<StringName> *p_classes);
314+
static void get_inheriters_from_class(const StringName &p_class, LocalVector<StringName> &p_classes);
315315
static void get_direct_inheriters_from_class(const StringName &p_class, List<StringName> *p_classes);
316316
static StringName get_parent_class_nocheck(const StringName &p_class);
317317
static bool get_inheritance_chain_nocheck(const StringName &p_class, Vector<StringName> &r_result);

editor/editor_audio_buses.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -974,8 +974,8 @@ EditorAudioBus::EditorAudioBus(EditorAudioBuses *p_buses, bool p_is_master) {
974974
effect_options->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); // Don't translate class names.
975975
effect_options->connect("index_pressed", callable_mp(this, &EditorAudioBus::_effect_add));
976976
add_child(effect_options);
977-
List<StringName> effect_list;
978-
ClassDB::get_inheriters_from_class("AudioEffect", &effect_list);
977+
LocalVector<StringName> effect_list;
978+
ClassDB::get_inheriters_from_class("AudioEffect", effect_list);
979979
effect_list.sort_custom<StringName::AlphCompare>();
980980
for (const StringName &E : effect_list) {
981981
if (!ClassDB::can_instantiate(E) || ClassDB::is_virtual(E)) {

editor/editor_resource_picker.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -607,8 +607,8 @@ static void _add_allowed_type(const StringName &p_type, List<StringName> *p_vect
607607
p_vector->push_back(p_type);
608608
}
609609

610-
List<StringName> inheriters;
611-
ClassDB::get_inheriters_from_class(p_type, &inheriters);
610+
LocalVector<StringName> inheriters;
611+
ClassDB::get_inheriters_from_class(p_type, inheriters);
612612
for (const StringName &S : inheriters) {
613613
_add_allowed_type(S, p_vector);
614614
}

editor/export/project_export.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1531,8 +1531,8 @@ ProjectExportDialog::ProjectExportDialog() {
15311531
resources_vb->add_child(server_strip_message);
15321532

15331533
{
1534-
List<StringName> resource_names;
1535-
ClassDB::get_inheriters_from_class("Resource", &resource_names);
1534+
LocalVector<StringName> resource_names;
1535+
ClassDB::get_inheriters_from_class("Resource", resource_names);
15361536

15371537
PackedStringArray strippable;
15381538
for (const StringName &resource_name : resource_names) {

editor/gui/scene_tree_editor.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1839,7 +1839,7 @@ Variant SceneTreeEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from
18391839
}
18401840

18411841
bool SceneTreeEditor::_is_script_type(const StringName &p_type) const {
1842-
return (script_types->find(p_type));
1842+
return (script_types->has(p_type));
18431843
}
18441844

18451845
bool SceneTreeEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
@@ -2144,8 +2144,8 @@ SceneTreeEditor::SceneTreeEditor(bool p_label, bool p_can_rename, bool p_can_ope
21442144
ask_before_revoke_checkbox->set_tooltip_text(TTR("This dialog can also be enabled/disabled in the Editor Settings: Docks > Scene Tree > Ask Before Revoking Unique Name."));
21452145
vb->add_child(ask_before_revoke_checkbox);
21462146

2147-
script_types = memnew(List<StringName>);
2148-
ClassDB::get_inheriters_from_class("Script", script_types);
2147+
script_types = memnew(LocalVector<StringName>);
2148+
ClassDB::get_inheriters_from_class("Script", *script_types);
21492149
}
21502150

21512151
SceneTreeEditor::~SceneTreeEditor() {

editor/gui/scene_tree_editor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ class SceneTreeEditor : public Control {
212212

213213
Timer *update_timer = nullptr;
214214

215-
List<StringName> *script_types;
215+
LocalVector<StringName> *script_types;
216216
bool _is_script_type(const StringName &p_type) const;
217217

218218
Vector<StringName> valid_types;

editor/plugins/animation_blend_space_1d_editor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ void AnimationNodeBlendSpace1DEditor::_blend_space_gui_input(const Ref<InputEven
7676
animations_menu->clear();
7777
animations_to_add.clear();
7878

79-
List<StringName> classes;
80-
ClassDB::get_inheriters_from_class("AnimationRootNode", &classes);
79+
LocalVector<StringName> classes;
80+
ClassDB::get_inheriters_from_class("AnimationRootNode", classes);
8181
classes.sort_custom<StringName::AlphCompare>();
8282

8383
menu->add_submenu_node_item(TTR("Add Animation"), animations_menu);

editor/plugins/animation_blend_space_2d_editor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,10 @@ void AnimationNodeBlendSpace2DEditor::_blend_space_gui_input(const Ref<InputEven
119119
menu->clear(false);
120120
animations_menu->clear();
121121
animations_to_add.clear();
122-
List<StringName> classes;
122+
LocalVector<StringName> classes;
123123
classes.sort_custom<StringName::AlphCompare>();
124124

125-
ClassDB::get_inheriters_from_class("AnimationRootNode", &classes);
125+
ClassDB::get_inheriters_from_class("AnimationRootNode", classes);
126126
menu->add_submenu_node_item(TTR("Add Animation"), animations_menu);
127127

128128
List<StringName> names;

editor/plugins/animation_state_machine_editor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -631,8 +631,8 @@ void AnimationNodeStateMachineEditor::_open_menu(const Vector2 &p_position) {
631631
}
632632
}
633633

634-
List<StringName> classes;
635-
ClassDB::get_inheriters_from_class("AnimationRootNode", &classes);
634+
LocalVector<StringName> classes;
635+
ClassDB::get_inheriters_from_class("AnimationRootNode", classes);
636636
classes.sort_custom<StringName::AlphCompare>();
637637

638638
for (const StringName &class_name : classes) {

modules/gdscript/gdscript_editor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -921,8 +921,8 @@ static void _find_annotation_arguments(const GDScriptParser::AnnotationNode *p_a
921921
node.insert_text = node.display.quote(p_quote_style);
922922
r_result.insert(node.display, node);
923923

924-
List<StringName> native_classes;
925-
ClassDB::get_inheriters_from_class("Node", &native_classes);
924+
LocalVector<StringName> native_classes;
925+
ClassDB::get_inheriters_from_class("Node", native_classes);
926926
for (const StringName &E : native_classes) {
927927
if (!ClassDB::is_class_exposed(E)) {
928928
continue;

0 commit comments

Comments
 (0)