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:
@ -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;
|
||||
|
||||
|
||||
@ -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");
|
||||
}
|
||||
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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");
|
||||
}
|
||||
|
||||
|
||||
@ -187,7 +187,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++) {
|
||||
@ -200,7 +200,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();
|
||||
@ -212,7 +212,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;
|
||||
|
||||
Reference in New Issue
Block a user