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 --- drivers/unix/os_unix.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'drivers/unix/os_unix.cpp') diff --git a/drivers/unix/os_unix.cpp b/drivers/unix/os_unix.cpp index 0a79c8014b..ce2553456d 100644 --- a/drivers/unix/os_unix.cpp +++ b/drivers/unix/os_unix.cpp @@ -546,8 +546,8 @@ Dictionary OS_Unix::execute_with_pipe(const String &p_path, const List & // The child process. Vector cs; cs.push_back(p_path.utf8()); - for (int i = 0; i < p_arguments.size(); i++) { - cs.push_back(p_arguments[i].utf8()); + for (const String &arg : p_arguments) { + cs.push_back(arg.utf8()); } Vector args; @@ -606,8 +606,8 @@ Error OS_Unix::execute(const String &p_path, const List &p_arguments, St #else if (r_pipe) { String command = "\"" + p_path + "\""; - for (int i = 0; i < p_arguments.size(); i++) { - command += String(" \"") + p_arguments[i] + "\""; + for (const String &arg : p_arguments) { + command += String(" \"") + arg + "\""; } if (read_stderr) { command += " 2>&1"; // Include stderr @@ -647,8 +647,8 @@ Error OS_Unix::execute(const String &p_path, const List &p_arguments, St // The child process Vector cs; cs.push_back(p_path.utf8()); - for (int i = 0; i < p_arguments.size(); i++) { - cs.push_back(p_arguments[i].utf8()); + for (const String &arg : p_arguments) { + cs.push_back(arg.utf8()); } Vector args; @@ -689,8 +689,8 @@ Error OS_Unix::create_process(const String &p_path, const List &p_argume Vector cs; cs.push_back(p_path.utf8()); - for (int i = 0; i < p_arguments.size(); i++) { - cs.push_back(p_arguments[i].utf8()); + for (const String &arg : p_arguments) { + cs.push_back(arg.utf8()); } Vector args; -- cgit v1.2.3