summaryrefslogtreecommitdiffstats
path: root/core/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 /core/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 'core/debugger')
-rw-r--r--core/debugger/debugger_marshalls.cpp8
-rw-r--r--core/debugger/remote_debugger.cpp3
-rw-r--r--core/debugger/remote_debugger_peer.cpp4
3 files changed, 7 insertions, 8 deletions
diff --git a/core/debugger/debugger_marshalls.cpp b/core/debugger/debugger_marshalls.cpp
index 3e6b7501c7..f4283e0ea9 100644
--- a/core/debugger/debugger_marshalls.cpp
+++ b/core/debugger/debugger_marshalls.cpp
@@ -38,10 +38,10 @@
Array DebuggerMarshalls::ScriptStackDump::serialize() {
Array arr;
arr.push_back(frames.size() * 3);
- for (int i = 0; i < frames.size(); i++) {
- arr.push_back(frames[i].file);
- arr.push_back(frames[i].line);
- arr.push_back(frames[i].func);
+ for (const ScriptLanguage::StackInfo &frame : frames) {
+ arr.push_back(frame.file);
+ arr.push_back(frame.line);
+ arr.push_back(frame.func);
}
return arr;
}
diff --git a/core/debugger/remote_debugger.cpp b/core/debugger/remote_debugger.cpp
index 1973663c72..bd30da3047 100644
--- a/core/debugger/remote_debugger.cpp
+++ b/core/debugger/remote_debugger.cpp
@@ -206,8 +206,7 @@ void RemoteDebugger::flush_output() {
Vector<String> joined_log_strings;
Vector<String> strings;
Vector<int> types;
- for (int i = 0; i < output_strings.size(); i++) {
- const OutputString &output_string = output_strings[i];
+ for (const OutputString &output_string : output_strings) {
if (output_string.type == MESSAGE_TYPE_ERROR) {
if (!joined_log_strings.is_empty()) {
strings.push_back(String("\n").join(joined_log_strings));
diff --git a/core/debugger/remote_debugger_peer.cpp b/core/debugger/remote_debugger_peer.cpp
index 81ee09f515..21a9014626 100644
--- a/core/debugger/remote_debugger_peer.cpp
+++ b/core/debugger/remote_debugger_peer.cpp
@@ -45,7 +45,7 @@ bool RemoteDebuggerPeerTCP::has_message() {
Array RemoteDebuggerPeerTCP::get_message() {
MutexLock lock(mutex);
ERR_FAIL_COND_V(!has_message(), Array());
- Array out = in_queue[0];
+ Array out = in_queue.front()->get();
in_queue.pop_front();
return out;
}
@@ -100,7 +100,7 @@ void RemoteDebuggerPeerTCP::_write_out() {
break; // Nothing left to send
}
mutex.lock();
- Variant var = out_queue[0];
+ Variant var = out_queue.front()->get();
out_queue.pop_front();
mutex.unlock();
int size = 0;