Preallocate vectors with known size.

This commit is contained in:
Dubhghlas McLaughlin
2025-05-22 16:14:28 -05:00
parent 63ca87f9ff
commit c97ca14537
7 changed files with 285 additions and 157 deletions

View File

@@ -428,8 +428,9 @@ public:
option.location = op["location"];
if (op.has("matches")) {
PackedInt32Array matches = op["matches"];
ERR_CONTINUE(matches.size() & 1);
for (int j = 0; j < matches.size(); j += 2) {
size_t matches_size = matches.size();
ERR_CONTINUE(matches_size & 1);
for (size_t j = 0; j < matches_size; j += 2) {
option.matches.push_back(Pair<int, int>(matches[j], matches[j + 1]));
}
}

View File

@@ -390,11 +390,15 @@ void UndoRedo::_process_operation_list(List<Operation>::Element *E, bool p_execu
} else {
args.clear();
for (int i = 0; i < binds.size(); i++) {
args.push_back(&binds[i]);
size_t binds_size = binds.size();
args.resize(binds_size);
for (size_t i = 0; i < binds_size; i++) {
args[i] = &binds[i];
}
method_callback(method_callback_ud, obj, op.name, args.ptr(), binds.size());
method_callback(method_callback_ud, obj, op.name, args.ptr(), binds_size);
}
}
} break;