Do not iterate Dictionary with get_key_at_index.

This commit is contained in:
Yufeng Ying
2025-03-14 03:54:04 +08:00
parent af2c713971
commit bbc380b07e
6 changed files with 27 additions and 27 deletions

View File

@@ -549,12 +549,12 @@ Node *SceneState::instantiate(GenEditState p_edit_state) const {
bool convert_value = dict.get_typed_value_builtin() == Variant::OBJECT &&
ClassDB::is_parent_class(dict.get_typed_value_class_name(), "Node");
for (int i = 0; i < paths.size(); i++) {
Variant key = paths.get_key_at_index(i);
for (const KeyValue<Variant, Variant> &kv : paths) {
Variant key = kv.key;
if (convert_key) {
key = base->get_node_or_null(key);
}
Variant value = paths.get_value_at_index(i);
Variant value = kv.value;
if (convert_value) {
value = base->get_node_or_null(value);
}
@@ -881,14 +881,14 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Has
use_deferred_node_path_bit = true;
Dictionary dict = value;
Dictionary new_dict;
for (int i = 0; i < dict.size(); i++) {
Variant new_key = dict.get_key_at_index(i);
for (const KeyValue<Variant, Variant> &kv : dict) {
Variant new_key = kv.key;
if (convert_key && new_key.get_type() == Variant::OBJECT) {
if (Node *n = Object::cast_to<Node>(new_key)) {
new_key = p_node->get_path_to(n);
}
}
Variant new_value = dict.get_value_at_index(i);
Variant new_value = kv.value;
if (convert_value && new_value.get_type() == Variant::OBJECT) {
if (Node *n = Object::cast_to<Node>(new_value)) {
new_value = p_node->get_path_to(n);