diff options
author | Rémi Verschelde <remi@verschelde.fr> | 2021-07-22 12:13:10 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-22 12:13:10 +0200 |
commit | 6b1886f9983ac410aa9fb9262c4f4a099b2ae1ae (patch) | |
tree | 296302fe9b2bb2e2284123cbacfeb170066c1883 /core | |
parent | c40b4f2252ced6ebcbeeba232d77d254f75f8d8f (diff) | |
parent | ff40c3f3c8e71ce62afb3c14003a291a272fa7a8 (diff) | |
download | redot-engine-6b1886f9983ac410aa9fb9262c4f4a099b2ae1ae.tar.gz |
Merge pull request #50319 from nekomatata/optimize-node-path-check
Optimize NodePath update when renaming or deleting nodes in the editor
Diffstat (limited to 'core')
-rw-r--r-- | core/string/node_path.cpp | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/core/string/node_path.cpp b/core/string/node_path.cpp index d3afa7b4dd..5fae13779e 100644 --- a/core/string/node_path.cpp +++ b/core/string/node_path.cpp @@ -240,19 +240,26 @@ NodePath NodePath::rel_path_to(const NodePath &p_np) const { common_parent--; Vector<StringName> relpath; + relpath.resize(src_dirs.size() + dst_dirs.size() + 1); - for (int i = src_dirs.size() - 1; i > common_parent; i--) { - relpath.push_back(".."); + StringName *relpath_ptr = relpath.ptrw(); + + int path_size = 0; + StringName back_str(".."); + for (int i = common_parent + 1; i < src_dirs.size(); i++) { + relpath_ptr[path_size++] = back_str; } for (int i = common_parent + 1; i < dst_dirs.size(); i++) { - relpath.push_back(dst_dirs[i]); + relpath_ptr[path_size++] = dst_dirs[i]; } - if (relpath.size() == 0) { - relpath.push_back("."); + if (path_size == 0) { + relpath_ptr[path_size++] = "."; } + relpath.resize(path_size); + return NodePath(relpath, p_np.get_subnames(), false); } |