mirror of
https://github.com/godotengine/godot.git
synced 2026-01-03 18:11:19 +03: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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user