summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2024-05-07 09:04:44 +0200
committerRémi Verschelde <rverschelde@gmail.com>2024-05-07 09:04:44 +0200
commite63252b4219680d109bfa41c24f483e97b37f40e (patch)
tree8b8af6d7efcab9b2692d45dec65449fd83d2c8b9 /tests
parent570220ba9b127325f1a5aa7bb17d5c6f76ccf62c (diff)
parent955d5affa857ec1f358c56da8fb1ff4ab6590704 (diff)
downloadredot-engine-e63252b4219680d109bfa41c24f483e97b37f40e.tar.gz
Merge pull request #90705 from AThousandShips/foreach_list
Reduce and prevent unnecessary random-access to `List`
Diffstat (limited to 'tests')
-rw-r--r--tests/core/object/test_class_db.h14
-rw-r--r--tests/core/object/test_object.h2
-rw-r--r--tests/core/os/test_os.h4
-rw-r--r--tests/core/variant/test_dictionary.h2
-rw-r--r--tests/scene/test_sprite_frames.h5
-rw-r--r--tests/test_main.cpp6
6 files changed, 16 insertions, 17 deletions
diff --git a/tests/core/object/test_class_db.h b/tests/core/object/test_class_db.h
index 5623c1d495..fb62d0f056 100644
--- a/tests/core/object/test_class_db.h
+++ b/tests/core/object/test_class_db.h
@@ -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;
diff --git a/tests/core/object/test_object.h b/tests/core/object/test_object.h
index 3a3013a102..d714d71416 100644
--- a/tests/core/object/test_object.h
+++ b/tests/core/object/test_object.h
@@ -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");
}
diff --git a/tests/core/os/test_os.h b/tests/core/os/test_os.h
index 63f8b18238..6ee0ff82e7 100644
--- a/tests/core/os/test_os.h
+++ b/tests/core/os/test_os.h
@@ -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;
}
diff --git a/tests/core/variant/test_dictionary.h b/tests/core/variant/test_dictionary.h
index 5bc56075da..aba20972d9 100644
--- a/tests/core/variant/test_dictionary.h
+++ b/tests/core/variant/test_dictionary.h
@@ -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);
diff --git a/tests/scene/test_sprite_frames.h b/tests/scene/test_sprite_frames.h
index bf127cd42c..55854b90e4 100644
--- a/tests/scene/test_sprite_frames.h
+++ b/tests/scene/test_sprite_frames.h
@@ -74,9 +74,10 @@ TEST_CASE("[SpriteFrames] Animation addition, list getter, renaming, removal, an
sname_list.size() == test_names.size(),
"StringName List getter returned list of expected size");
- for (int i = 0; i < test_names.size(); i++) {
+ int idx = 0;
+ for (List<StringName>::ConstIterator itr = sname_list.begin(); itr != sname_list.end(); ++itr, ++idx) {
CHECK_MESSAGE(
- sname_list[i] == StringName(test_names[i]),
+ *itr == StringName(test_names[idx]),
"StringName List getter returned expected values");
}
diff --git a/tests/test_main.cpp b/tests/test_main.cpp
index 3a4ae3369d..69d8113e64 100644
--- a/tests/test_main.cpp
+++ b/tests/test_main.cpp
@@ -188,7 +188,7 @@ int test_main(int argc, char *argv[]) {
}
// Doctest runner.
doctest::Context test_context;
- List<String> test_args;
+ LocalVector<String> test_args;
// Clean arguments of "--test" from the args.
for (int x = 0; x < argc; x++) {
@@ -201,7 +201,7 @@ int test_main(int argc, char *argv[]) {
if (test_args.size() > 0) {
// Convert Godot command line arguments back to standard arguments.
char **doctest_args = new char *[test_args.size()];
- for (int x = 0; x < test_args.size(); x++) {
+ for (uint32_t x = 0; x < test_args.size(); x++) {
// Operation to convert Godot string to non wchar string.
CharString cs = test_args[x].utf8();
const char *str = cs.get_data();
@@ -213,7 +213,7 @@ int test_main(int argc, char *argv[]) {
test_context.applyCommandLine(test_args.size(), doctest_args);
- for (int x = 0; x < test_args.size(); x++) {
+ for (uint32_t x = 0; x < test_args.size(); x++) {
delete[] doctest_args[x];
}
delete[] doctest_args;