1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-06 12:20:30 +00:00

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

@@ -1025,8 +1025,7 @@ void AnimationPlayerEditor::_update_name_dialog_library_dropdown() {
}
int current_lib_id = index_offset; // Don't default to [Global] if it doesn't exist yet.
for (int i = 0; i < libraries.size(); i++) {
StringName library_name = libraries[i];
for (const StringName &library_name : libraries) {
if (!EditorNode::get_singleton()->is_resource_read_only(player->get_animation_library(library_name))) {
library->add_item((library_name == StringName()) ? String(TTR("[Global]")) : String(library_name));
library->set_item_metadata(valid_library_count, String(library_name));
@@ -1043,8 +1042,7 @@ void AnimationPlayerEditor::_update_name_dialog_library_dropdown() {
// one which isn't a read-only library.
bool auto_assigning_non_global_library = false;
if (current_library_name == StringName() && valid_library_count > 0) {
for (int i = 0; i < libraries.size(); i++) {
StringName library_name = libraries[i];
for (const StringName &library_name : libraries) {
if (!EditorNode::get_singleton()->is_resource_read_only(player->get_animation_library(library_name))) {
current_library_name = library_name;
current_lib_id = 0;