diff options
author | A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> | 2024-04-15 15:18:34 +0200 |
---|---|---|
committer | A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> | 2024-05-04 16:08:55 +0200 |
commit | 955d5affa857ec1f358c56da8fb1ff4ab6590704 (patch) | |
tree | b667ac9f6f62bff17ce032683c0eb09727660555 /core/extension | |
parent | 7ebc866418b075df58cbe4e31fcf8b0c3acd70a1 (diff) | |
download | redot-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/extension')
-rw-r--r-- | core/extension/extension_api_dump.cpp | 35 | ||||
-rw-r--r-- | core/extension/gdextension.cpp | 11 |
2 files changed, 28 insertions, 18 deletions
diff --git a/core/extension/extension_api_dump.cpp b/core/extension/extension_api_dump.cpp index d7fba74365..1c9b4dc3e8 100644 --- a/core/extension/extension_api_dump.cpp +++ b/core/extension/extension_api_dump.cpp @@ -1018,26 +1018,34 @@ Dictionary GDExtensionAPIDump::generate_extension_api(bool p_include_docs) { d2["is_virtual"] = true; // virtual functions have no hash since no MethodBind is involved bool has_return = mi.return_val.type != Variant::NIL || (mi.return_val.usage & PROPERTY_USAGE_NIL_IS_VARIANT); - Array arguments; - for (int i = (has_return ? -1 : 0); i < mi.arguments.size(); i++) { - PropertyInfo pinfo = i == -1 ? mi.return_val : mi.arguments[i]; + if (has_return) { + PropertyInfo pinfo = mi.return_val; Dictionary d3; - if (i >= 0) { - d3["name"] = pinfo.name; + d3["type"] = get_property_info_type_name(pinfo); + + if (mi.get_argument_meta(-1) > 0) { + d3["meta"] = get_type_meta_name((GodotTypeInfo::Metadata)mi.get_argument_meta(-1)); } + d2["return_value"] = d3; + } + + Array arguments; + int i = 0; + for (List<PropertyInfo>::ConstIterator itr = mi.arguments.begin(); itr != mi.arguments.end(); ++itr, ++i) { + const PropertyInfo &pinfo = *itr; + Dictionary d3; + + d3["name"] = pinfo.name; + d3["type"] = get_property_info_type_name(pinfo); if (mi.get_argument_meta(i) > 0) { d3["meta"] = get_type_meta_name((GodotTypeInfo::Metadata)mi.get_argument_meta(i)); } - if (i == -1) { - d2["return_value"] = d3; - } else { - arguments.push_back(d3); - } + arguments.push_back(d3); } if (arguments.size()) { @@ -1151,10 +1159,11 @@ Dictionary GDExtensionAPIDump::generate_extension_api(bool p_include_docs) { Array arguments; - for (int i = 0; i < F.arguments.size(); i++) { + int i = 0; + for (List<PropertyInfo>::ConstIterator itr = F.arguments.begin(); itr != F.arguments.end(); ++itr, ++i) { Dictionary d3; - d3["name"] = F.arguments[i].name; - d3["type"] = get_property_info_type_name(F.arguments[i]); + d3["name"] = itr->name; + d3["type"] = get_property_info_type_name(*itr); if (F.get_argument_meta(i) > 0) { d3["meta"] = get_type_meta_name((GodotTypeInfo::Metadata)F.get_argument_meta(i)); } diff --git a/core/extension/gdextension.cpp b/core/extension/gdextension.cpp index b48ea97040..a26bb3e8f3 100644 --- a/core/extension/gdextension.cpp +++ b/core/extension/gdextension.cpp @@ -211,14 +211,14 @@ protected: if (p_arg < 0) { return return_value_info.type; } else { - return arguments_info[p_arg].type; + return arguments_info.get(p_arg).type; } } virtual PropertyInfo _gen_argument_type_info(int p_arg) const override { if (p_arg < 0) { return return_value_info; } else { - return arguments_info[p_arg]; + return arguments_info.get(p_arg); } } @@ -232,7 +232,7 @@ public: if (p_arg < 0) { return return_value_metadata; } else { - return arguments_metadata[p_arg]; + return arguments_metadata.get(p_arg); } } #endif @@ -319,8 +319,9 @@ public: return false; } - for (uint32_t i = 0; i < p_method_info->argument_count; i++) { - if (arguments_info[i].type != (Variant::Type)p_method_info->arguments_info[i].type) { + List<PropertyInfo>::ConstIterator itr = arguments_info.begin(); + for (uint32_t i = 0; i < p_method_info->argument_count; ++itr, ++i) { + if (itr->type != (Variant::Type)p_method_info->arguments_info[i].type) { return false; } } |