summaryrefslogtreecommitdiffstats
path: root/editor/debugger
diff options
context:
space:
mode:
authorA Thousand Ships <96648715+AThousandShips@users.noreply.github.com>2024-04-15 15:18:34 +0200
committerA Thousand Ships <96648715+AThousandShips@users.noreply.github.com>2024-05-04 16:08:55 +0200
commit955d5affa857ec1f358c56da8fb1ff4ab6590704 (patch)
treeb667ac9f6f62bff17ce032683c0eb09727660555 /editor/debugger
parent7ebc866418b075df58cbe4e31fcf8b0c3acd70a1 (diff)
downloadredot-engine-955d5affa857ec1f358c56da8fb1ff4ab6590704.tar.gz
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
Diffstat (limited to 'editor/debugger')
-rw-r--r--editor/debugger/debug_adapter/debug_adapter_parser.cpp5
-rw-r--r--editor/debugger/debug_adapter/debug_adapter_protocol.cpp2
-rw-r--r--editor/debugger/editor_debugger_inspector.cpp6
-rw-r--r--editor/debugger/editor_debugger_tree.cpp13
-rw-r--r--editor/debugger/script_editor_debugger.cpp19
5 files changed, 23 insertions, 22 deletions
diff --git a/editor/debugger/debug_adapter/debug_adapter_parser.cpp b/editor/debugger/debug_adapter/debug_adapter_parser.cpp
index b75e5c1c0d..3c0420d2f0 100644
--- a/editor/debugger/debug_adapter/debug_adapter_parser.cpp
+++ b/editor/debugger/debug_adapter/debug_adapter_parser.cpp
@@ -407,9 +407,10 @@ Dictionary DebugAdapterParser::req_scopes(const Dictionary &p_params) const {
HashMap<DAP::StackFrame, List<int>, DAP::StackFrame>::Iterator E = DebugAdapterProtocol::get_singleton()->stackframe_list.find(frame);
if (E) {
ERR_FAIL_COND_V(E->value.size() != 3, prepare_error_response(p_params, DAP::ErrorType::UNKNOWN));
- for (int i = 0; i < 3; i++) {
+ List<int>::ConstIterator itr = E->value.begin();
+ for (int i = 0; i < 3; ++itr, ++i) {
DAP::Scope scope;
- scope.variablesReference = E->value[i];
+ scope.variablesReference = *itr;
switch (i) {
case 0:
scope.name = "Locals";
diff --git a/editor/debugger/debug_adapter/debug_adapter_protocol.cpp b/editor/debugger/debug_adapter/debug_adapter_protocol.cpp
index c86ca7aaad..56cb3b6c73 100644
--- a/editor/debugger/debug_adapter/debug_adapter_protocol.cpp
+++ b/editor/debugger/debug_adapter/debug_adapter_protocol.cpp
@@ -967,7 +967,7 @@ void DebugAdapterProtocol::on_debug_stack_frame_var(const Array &p_data) {
List<int> scope_ids = stackframe_list.find(frame)->value;
ERR_FAIL_COND(scope_ids.size() != 3);
ERR_FAIL_INDEX(stack_var.type, 3);
- int var_id = scope_ids[stack_var.type];
+ int var_id = scope_ids.get(stack_var.type);
DAP::Variable variable;
diff --git a/editor/debugger/editor_debugger_inspector.cpp b/editor/debugger/editor_debugger_inspector.cpp
index b2fd84d2ed..816bd6b72c 100644
--- a/editor/debugger/editor_debugger_inspector.cpp
+++ b/editor/debugger/editor_debugger_inspector.cpp
@@ -146,9 +146,9 @@ ObjectID EditorDebuggerInspector::add_object(const Array &p_arr) {
debug_obj->prop_list.clear();
int new_props_added = 0;
HashSet<String> changed;
- for (int i = 0; i < obj.properties.size(); i++) {
- PropertyInfo &pinfo = obj.properties[i].first;
- Variant &var = obj.properties[i].second;
+ for (SceneDebuggerObject::SceneDebuggerProperty &property : obj.properties) {
+ PropertyInfo &pinfo = property.first;
+ Variant &var = property.second;
if (pinfo.type == Variant::OBJECT) {
if (var.get_type() == Variant::STRING) {
diff --git a/editor/debugger/editor_debugger_tree.cpp b/editor/debugger/editor_debugger_tree.cpp
index de2e51ee81..63053d2574 100644
--- a/editor/debugger/editor_debugger_tree.cpp
+++ b/editor/debugger/editor_debugger_tree.cpp
@@ -147,17 +147,16 @@ void EditorDebuggerTree::update_scene_tree(const SceneDebuggerTree *p_tree, int
// Nodes are in a flatten list, depth first. Use a stack of parents, avoid recursion.
List<Pair<TreeItem *, int>> parents;
- for (int i = 0; i < p_tree->nodes.size(); i++) {
+ for (const SceneDebuggerTree::RemoteNode &node : p_tree->nodes) {
TreeItem *parent = nullptr;
if (parents.size()) { // Find last parent.
- Pair<TreeItem *, int> &p = parents[0];
+ Pair<TreeItem *, int> &p = parents.front()->get();
parent = p.first;
if (!(--p.second)) { // If no child left, remove it.
parents.pop_front();
}
}
// Add this node.
- const SceneDebuggerTree::RemoteNode &node = p_tree->nodes[i];
TreeItem *item = create_item(parent);
item->set_text(0, node.name);
if (node.scene_file_path.is_empty()) {
@@ -244,8 +243,8 @@ void EditorDebuggerTree::update_scene_tree(const SceneDebuggerTree *p_tree, int
item = parent;
parent = item->get_parent();
// Check if parent expects more children.
- for (int j = 0; j < parents.size(); j++) {
- if (parents[j].first == item) {
+ for (const Pair<TreeItem *, int> &pair : parents) {
+ if (pair.first == item) {
parent = nullptr;
break; // Might have more children.
}
@@ -326,8 +325,8 @@ void EditorDebuggerTree::_item_menu_id_pressed(int p_option) {
Ref<PackedScene> sd = memnew(PackedScene);
ResourceSaver::get_recognized_extensions(sd, &extensions);
file_dialog->clear_filters();
- for (int i = 0; i < extensions.size(); i++) {
- file_dialog->add_filter("*." + extensions[i], extensions[i].to_upper());
+ for (const String &extension : extensions) {
+ file_dialog->add_filter("*." + extension, extension.to_upper());
}
String filename = get_selected_path().get_file() + "." + extensions.front()->get().to_lower();
diff --git a/editor/debugger/script_editor_debugger.cpp b/editor/debugger/script_editor_debugger.cpp
index 2b880274f8..d5cf887a4e 100644
--- a/editor/debugger/script_editor_debugger.cpp
+++ b/editor/debugger/script_editor_debugger.cpp
@@ -440,13 +440,14 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, uint64_t p_thread
Array stack_dump_info;
- for (int i = 0; i < stack.frames.size(); i++) {
+ int i = 0;
+ for (List<ScriptLanguage::StackInfo>::Iterator itr = stack.frames.begin(); itr != stack.frames.end(); ++itr, ++i) {
TreeItem *s = stack_dump->create_item(r);
Dictionary d;
d["frame"] = i;
- d["file"] = stack.frames[i].file;
- d["function"] = stack.frames[i].func;
- d["line"] = stack.frames[i].line;
+ d["file"] = itr->file;
+ d["function"] = itr->func;
+ d["line"] = itr->line;
stack_dump_info.push_back(d);
s->set_metadata(0, d);
@@ -725,20 +726,20 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, uint64_t p_thread
metric.categories.push_back(frame_time);
}
- for (int i = 0; i < frame.servers.size(); i++) {
- const ServersDebugger::ServerInfo &srv = frame.servers[i];
+ for (const ServersDebugger::ServerInfo &srv : frame.servers) {
EditorProfiler::Metric::Category c;
const String name = srv.name;
c.name = EditorPropertyNameProcessor::get_singleton()->process_name(name, EditorPropertyNameProcessor::STYLE_CAPITALIZED);
c.items.resize(srv.functions.size());
c.total_time = 0;
c.signature = "categ::" + name;
- for (int j = 0; j < srv.functions.size(); j++) {
+ int j = 0;
+ for (List<ServersDebugger::ServerFunctionInfo>::ConstIterator itr = srv.functions.begin(); itr != srv.functions.end(); ++itr, ++j) {
EditorProfiler::Metric::Category::Item item;
item.calls = 1;
item.line = 0;
- item.name = srv.functions[j].name;
- item.self = srv.functions[j].time;
+ item.name = itr->name;
+ item.self = itr->time;
item.total = item.self;
item.signature = "categ::" + name + "::" + item.name;
item.name = EditorPropertyNameProcessor::get_singleton()->process_name(item.name, EditorPropertyNameProcessor::STYLE_CAPITALIZED);