From 4285c44b47256095871467c3d7c102cab4bb61b7 Mon Sep 17 00:00:00 2001 From: Jason Knight Date: Mon, 9 Oct 2023 14:18:19 -0600 Subject: [PATCH] Far faster and more efficient method of checking if an identifer refers an autoload. --- modules/gdscript/gdscript_parser.cpp | 118 ++++++++++----------------- 1 file changed, 42 insertions(+), 76 deletions(-) diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index 93f9852602a..3cb3cd3495f 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -56,6 +56,21 @@ T *GDScriptParser::alloc_node() { return t; } +static String _lookup_autoload_path_for_identifier(const String &p_identifier) { + String autoload_path; + String autoload_setting_path = "autoload/" + p_identifier; + if (ProjectSettings::get_singleton()->has_setting(autoload_setting_path)) { + autoload_path = ProjectSettings::get_singleton()->get(autoload_setting_path); + if (autoload_path.begins_with("*")) { + autoload_path = autoload_path.right(1); + } + if (!autoload_path.begins_with("res://")) { + autoload_path = "res://" + autoload_path; + } + } + return autoload_path; +} + #ifdef DEBUG_ENABLED static String _find_function_name(const GDScriptParser::OperatorNode *p_call); #endif // DEBUG_ENABLED @@ -5497,29 +5512,14 @@ void GDScriptParser::_determine_inheritance(ClassNode *p_class, bool p_recursive } p = nullptr; } else { - List props; - ProjectSettings::get_singleton()->get_property_list(&props); - for (List::Element *E = props.front(); E; E = E->next()) { - String s = E->get().name; - if (!s.begins_with("autoload/")) { - continue; - } - String name = s.get_slice("/", 1); - if (name == base) { - String singleton_path = ProjectSettings::get_singleton()->get(s); - if (singleton_path.begins_with("*")) { - singleton_path = singleton_path.right(1); - } - if (!singleton_path.begins_with("res://")) { - singleton_path = "res://" + singleton_path; - } - base_script = ResourceLoader::load(singleton_path); - if (!base_script.is_valid()) { - _set_error("Class '" + base + "' could not be fully loaded (script error or cyclic inheritance).", p_class->line); - return; - } - p = nullptr; + String autoload_path = _lookup_autoload_path_for_identifier(base); + if (!autoload_path.empty()) { + base_script = ResourceLoader::load(autoload_path); + if (!base_script.is_valid()) { + _set_error("Class '" + base + "' could not be fully loaded (script error or cyclic inheritance).", p_class->line); + return; } + p = nullptr; } } @@ -5869,28 +5869,10 @@ GDScriptParser::DataType GDScriptParser::_resolve_type(const DataType &p_source, name_part++; continue; } - List props; - ProjectSettings::get_singleton()->get_property_list(&props); - String singleton_path; - for (List::Element *E = props.front(); E; E = E->next()) { - String s = E->get().name; - if (!s.begins_with("autoload/")) { - continue; - } - String name = s.get_slice("/", 1); - if (name == id) { - singleton_path = ProjectSettings::get_singleton()->get(s); - if (singleton_path.begins_with("*")) { - singleton_path = singleton_path.right(1); - } - if (!singleton_path.begins_with("res://")) { - singleton_path = "res://" + singleton_path; - } - break; - } - } - if (!singleton_path.empty()) { - Ref