summaryrefslogtreecommitdiffstats
path: root/core/io/ip.cpp
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/io/ip.cpp
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/io/ip.cpp')
-rw-r--r--core/io/ip.cpp16
1 files changed, 8 insertions, 8 deletions
diff --git a/core/io/ip.cpp b/core/io/ip.cpp
index ec86104926..f20d65bef9 100644
--- a/core/io/ip.cpp
+++ b/core/io/ip.cpp
@@ -148,8 +148,8 @@ PackedStringArray IP::resolve_hostname_addresses(const String &p_hostname, Type
resolver->mutex.unlock();
PackedStringArray result;
- for (int i = 0; i < res.size(); ++i) {
- result.push_back(String(res[i]));
+ for (const IPAddress &E : res) {
+ result.push_back(String(E));
}
return result;
}
@@ -206,9 +206,9 @@ IPAddress IP::get_resolve_item_address(ResolverID p_id) const {
List<IPAddress> res = resolver->queue[p_id].response;
- for (int i = 0; i < res.size(); ++i) {
- if (res[i].is_valid()) {
- return res[i];
+ for (const IPAddress &E : res) {
+ if (E.is_valid()) {
+ return E;
}
}
return IPAddress();
@@ -226,9 +226,9 @@ Array IP::get_resolve_item_addresses(ResolverID p_id) const {
List<IPAddress> res = resolver->queue[p_id].response;
Array result;
- for (int i = 0; i < res.size(); ++i) {
- if (res[i].is_valid()) {
- result.push_back(String(res[i]));
+ for (const IPAddress &E : res) {
+ if (E.is_valid()) {
+ result.push_back(String(E));
}
}
return result;