Merge pull request #56957 from Pineapple/get-node-error-check-optimization

Rework Node::get_node to omit is_absolute() check in best case scenario
This commit is contained in:
Rémi Verschelde 2022-01-20 07:34:15 +01:00 committed by GitHub
commit 28fcbdd6dd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

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