Merge pull request #50319 from nekomatata/optimize-node-path-check

Optimize NodePath update when renaming or deleting nodes in the editor
This commit is contained in:
Rémi Verschelde
2021-07-22 12:13:10 +02:00
committed by GitHub
3 changed files with 110 additions and 124 deletions

View File

@@ -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);
}