summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <remi@verschelde.fr>2022-01-20 07:34:15 +0100
committerGitHub <noreply@github.com>2022-01-20 07:34:15 +0100
commit28fcbdd6dd9d40d8dd020f3ae542db89f1cb7e46 (patch)
tree08f9efbf921acf8ae2235554325c2b749696d86b
parenteab8c071141b82fb143eae78a16a707c03bcd2aa (diff)
parente2792cc71caa89997c0127abd5bb4b0e19d67f46 (diff)
Merge pull request #56957 from Pineapple/get-node-error-check-optimization
Rework Node::get_node to omit is_absolute() check in best case scenario
-rw-r--r--scene/main/node.cpp14
1 files changed, 8 insertions, 6 deletions
diff --git a/scene/main/node.cpp b/scene/main/node.cpp
index 9d96c71113..416dec3e4f 100644
--- a/scene/main/node.cpp
+++ b/scene/main/node.cpp
@@ -1316,12 +1316,14 @@ Node *Node::get_node_or_null(const NodePath &p_path) const {
Node *Node::get_node(const NodePath &p_path) const {
Node *node = get_node_or_null(p_path);
- if (p_path.is_absolute()) {
- ERR_FAIL_COND_V_MSG(!node, nullptr,
- vformat(R"(Node not found: "%s" (absolute path attempted from "%s").)", p_path, get_path()));
- } else {
- ERR_FAIL_COND_V_MSG(!node, nullptr,
- vformat(R"(Node not found: "%s" (relative to "%s").)", p_path, get_path()));
+ if (unlikely(!node)) {
+ if (p_path.is_absolute()) {
+ ERR_FAIL_V_MSG(nullptr,
+ vformat(R"(Node not found: "%s" (absolute path attempted from "%s").)", p_path, get_path()));
+ } else {
+ ERR_FAIL_V_MSG(nullptr,
+ vformat(R"(Node not found: "%s" (relative to "%s").)", p_path, get_path()));
+ }
}
return node;