From d16413a34690f11b0de7fdc54c28143e2f0ae927 Mon Sep 17 00:00:00 2001 From: Luo Zhihao Date: Sat, 13 Sep 2025 09:06:10 +0800 Subject: [PATCH] Optimize NodePath to String by using cahced path --- core/string/node_path.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/core/string/node_path.cpp b/core/string/node_path.cpp index 3ff12103627..44ba38236a0 100644 --- a/core/string/node_path.cpp +++ b/core/string/node_path.cpp @@ -52,6 +52,7 @@ void NodePath::_update_hash_cache() const { void NodePath::prepend_period() { if (data->path.size() && data->path[0].operator String() != ".") { data->path.insert(0, "."); + data->concatenated_path = StringName(); data->hash_cache_valid = false; } } @@ -179,15 +180,11 @@ NodePath::operator String() const { ret = "/"; } - for (int i = 0; i < data->path.size(); i++) { - if (i > 0) { - ret += "/"; - } - ret += data->path[i].operator String(); - } + ret += get_concatenated_names(); - for (int i = 0; i < data->subpath.size(); i++) { - ret += ":" + data->subpath[i].operator String(); + String subpath = get_concatenated_subnames(); + if (!subpath.is_empty()) { + ret += ":" + subpath; } return ret; @@ -356,6 +353,7 @@ void NodePath::simplify() { } } } + data->concatenated_path = StringName(); data->hash_cache_valid = false; }