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
This commit is contained in:
A Thousand Ships
2024-04-15 15:18:34 +02:00
parent 7ebc866418
commit 955d5affa8
103 changed files with 877 additions and 849 deletions

View File

@ -510,7 +510,7 @@ void ExtendGDScriptParser::parse_function_symbol(const GDScriptParser::FunctionN
node_stack.push_back(p_func->body);
while (!node_stack.is_empty()) {
GDScriptParser::Node *node = node_stack[0];
GDScriptParser::Node *node = node_stack.front()->get();
node_stack.pop_front();
switch (node->type) {

View File

@ -223,7 +223,7 @@ void GDScriptWorkspace::reload_all_workspace_scripts() {
HashMap<String, ExtendGDScriptParser *>::Iterator S = parse_results.find(path);
String err_msg = "Failed parse script " + path;
if (S) {
err_msg += "\n" + S->value->get_errors()[0].message;
err_msg += "\n" + S->value->get_errors().front()->get().message;
}
ERR_CONTINUE_MSG(err != OK, err_msg);
}
@ -619,8 +619,8 @@ Node *GDScriptWorkspace::_get_owner_scene_node(String p_path) {
_get_owners(EditorFileSystem::get_singleton()->get_filesystem(), p_path, owners);
for (int i = 0; i < owners.size(); i++) {
NodePath owner_path = owners[i];
for (const String &owner : owners) {
NodePath owner_path = owner;
Ref<Resource> owner_res = ResourceLoader::load(owner_path);
if (Object::cast_to<PackedScene>(owner_res.ptr())) {
Ref<PackedScene> owner_packed_scene = Ref<PackedScene>(Object::cast_to<PackedScene>(*owner_res));