From 955d5affa857ec1f358c56da8fb1ff4ab6590704 Mon Sep 17 00:00:00 2001 From: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> Date: Mon, 15 Apr 2024 15:18:34 +0200 Subject: Reduce and prevent unnecessary random-access to `List` Random-access access to `List` when iterating is `O(n^2)` (`O(n)` when accessing a single element) * Removed subscript operator, in favor of a more explicit `get` * Added conversion from `Iterator` to `ConstIterator` * Remade existing operations into other solutions when applicable --- modules/gdscript/gdscript_editor.cpp | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) (limited to 'modules/gdscript/gdscript_editor.cpp') diff --git a/modules/gdscript/gdscript_editor.cpp b/modules/gdscript/gdscript_editor.cpp index 74d383c57f..9caf772b5c 100644 --- a/modules/gdscript/gdscript_editor.cpp +++ b/modules/gdscript/gdscript_editor.cpp @@ -2733,9 +2733,9 @@ static void _find_call_arguments(GDScriptParser::CompletionContext &p_context, c // Handle user preference. if (opt.is_quoted()) { opt = opt.unquote().quote(quote_style); - if (use_string_names && info.arguments[p_argidx].type == Variant::STRING_NAME) { + if (use_string_names && info.arguments.get(p_argidx).type == Variant::STRING_NAME) { opt = opt.indent("&"); - } else if (use_node_paths && info.arguments[p_argidx].type == Variant::NODE_PATH) { + } else if (use_node_paths && info.arguments.get(p_argidx).type == Variant::NODE_PATH) { opt = opt.indent("^"); } } @@ -2746,7 +2746,7 @@ static void _find_call_arguments(GDScriptParser::CompletionContext &p_context, c } if (p_argidx < method_args) { - PropertyInfo arg_info = info.arguments[p_argidx]; + const PropertyInfo &arg_info = info.arguments.get(p_argidx); if (arg_info.usage & (PROPERTY_USAGE_CLASS_IS_ENUM | PROPERTY_USAGE_CLASS_IS_BITFIELD)) { _find_enumeration_candidates(p_context, arg_info.class_name, r_result); } @@ -3334,19 +3334,17 @@ static void _find_call_arguments(GDScriptParser::CompletionContext &p_context, c } method_hint += "("; - if (mi.arguments.size()) { - for (int i = 0; i < mi.arguments.size(); i++) { - if (i > 0) { - method_hint += ", "; - } - String arg = mi.arguments[i].name; - if (arg.contains(":")) { - arg = arg.substr(0, arg.find(":")); - } - method_hint += arg; - if (use_type_hint) { - method_hint += ": " + _get_visual_datatype(mi.arguments[i], true, class_name); - } + for (List::ConstIterator arg_itr = mi.arguments.begin(); arg_itr != mi.arguments.end(); ++arg_itr) { + if (arg_itr != mi.arguments.begin()) { + method_hint += ", "; + } + String arg = arg_itr->name; + if (arg.contains(":")) { + arg = arg.substr(0, arg.find(":")); + } + method_hint += arg; + if (use_type_hint) { + method_hint += ": " + _get_visual_datatype(*arg_itr, true, class_name); } } method_hint += ")"; -- cgit v1.2.3