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:
A Thousand Ships
2024-04-15 15:18:34 +02:00
parent 7ebc866418
commit 955d5affa8
103 changed files with 877 additions and 849 deletions

View File

@ -550,8 +550,6 @@ void add_exposed_classes(Context &r_context) {
for (const MethodInfo &E : method_list) {
const MethodInfo &method_info = E;
int argc = method_info.arguments.size();
if (method_info.name.is_empty()) {
continue;
}
@ -613,8 +611,9 @@ void add_exposed_classes(Context &r_context) {
method.return_type.name = Variant::get_type_name(return_info.type);
}
for (int i = 0; i < argc; i++) {
PropertyInfo arg_info = method_info.arguments[i];
int i = 0;
for (List<PropertyInfo>::ConstIterator itr = method_info.arguments.begin(); itr != method_info.arguments.end(); ++itr, ++i) {
const PropertyInfo &arg_info = *itr;
String orig_arg_name = arg_info.name;
@ -686,10 +685,9 @@ void add_exposed_classes(Context &r_context) {
TEST_FAIL_COND(!String(signal.name).is_valid_identifier(),
"Signal name is not a valid identifier: '", exposed_class.name, ".", signal.name, "'.");
int argc = method_info.arguments.size();
for (int i = 0; i < argc; i++) {
PropertyInfo arg_info = method_info.arguments[i];
int i = 0;
for (List<PropertyInfo>::ConstIterator itr = method_info.arguments.begin(); itr != method_info.arguments.end(); ++itr, ++i) {
const PropertyInfo &arg_info = *itr;
String orig_arg_name = arg_info.name;

View File

@ -142,7 +142,7 @@ TEST_CASE("[Object] Core getters") {
inheritance_list.size() == 1,
"The inheritance list should consist of Object only");
CHECK_MESSAGE(
inheritance_list[0] == "Object",
inheritance_list.front()->get() == "Object",
"The inheritance list should consist of Object only");
}

View File

@ -79,8 +79,8 @@ TEST_CASE("[OS] Non-UTF-8 environment variables") {
TEST_CASE("[OS] Command line arguments") {
List<String> arguments = OS::get_singleton()->get_cmdline_args();
bool found = false;
for (int i = 0; i < arguments.size(); i++) {
if (arguments[i] == "--test") {
for (const String &arg : arguments) {
if (arg == "--test") {
found = true;
break;
}

View File

@ -105,7 +105,7 @@ TEST_CASE("[Dictionary] get_key_lists()") {
map[1] = 3;
map.get_key_list(ptr);
CHECK(keys.size() == 1);
CHECK(int(keys[0]) == 1);
CHECK(int(keys.front()->get()) == 1);
map[2] = 4;
map.get_key_list(ptr);
CHECK(keys.size() == 3);