Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 8 additions & 17 deletions core/string/node_path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,9 @@ void NodePath::_update_hash_cache() const {
h = h ^ ssn[i].hash();
}

data->hash_cache_valid = true;
data->hash_cache = h;
}

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

bool NodePath::is_absolute() const {
if (!data) {
return false;
Expand Down Expand Up @@ -117,10 +108,8 @@ bool NodePath::operator==(const NodePath &p_path) const {
return false;
}

if (data->hash_cache_valid && p_path.data->hash_cache_valid) {
if (data->hash_cache != p_path.data->hash_cache) {
return false;
}
if (data->hash_cache != p_path.data->hash_cache) {
return false;
}

if (data->absolute != p_path.data->absolute) {
Expand Down Expand Up @@ -360,7 +349,7 @@ void NodePath::simplify() {
}
}
data->concatenated_path = StringName();
data->hash_cache_valid = false;
_update_hash_cache();
}

NodePath NodePath::simplified() const {
Expand All @@ -378,7 +367,7 @@ NodePath::NodePath(const Vector<StringName> &p_path, bool p_absolute) {
data->refcount.init();
data->absolute = p_absolute;
data->path = p_path;
data->hash_cache_valid = false;
_update_hash_cache();
}

NodePath::NodePath(const Vector<StringName> &p_path, const Vector<StringName> &p_subpath, bool p_absolute) {
Expand All @@ -391,7 +380,7 @@ NodePath::NodePath(const Vector<StringName> &p_path, const Vector<StringName> &p
data->absolute = p_absolute;
data->path = p_path;
data->subpath = p_subpath;
data->hash_cache_valid = false;
_update_hash_cache();
}

NodePath::NodePath(const NodePath &p_path) {
Expand Down Expand Up @@ -455,9 +444,9 @@ NodePath::NodePath(const String &p_path) {
data->refcount.init();
data->absolute = absolute;
data->subpath = subpath;
data->hash_cache_valid = false;

if (slices == 0) {
_update_hash_cache();
return;
}
data->path.resize(slices);
Expand All @@ -478,6 +467,8 @@ NodePath::NodePath(const String &p_path) {
last_is_slash = false;
}
}

_update_hash_cache();
}

NodePath::~NodePath() {
Expand Down
15 changes: 2 additions & 13 deletions core/string/node_path.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ class [[nodiscard]] NodePath {
StringName concatenated_path;
StringName concatenated_subpath;
bool absolute;
mutable bool hash_cache_valid;
mutable uint32_t hash_cache;
uint32_t hash_cache;
};

mutable Data *data = nullptr;
Expand All @@ -68,17 +67,7 @@ class [[nodiscard]] NodePath {
NodePath rel_path_to(const NodePath &p_np) const;
NodePath get_as_property_path() const;

void prepend_period();

_FORCE_INLINE_ uint32_t hash() const {
if (!data) {
return 0;
}
if (!data->hash_cache_valid) {
_update_hash_cache();
}
return data->hash_cache;
}
_FORCE_INLINE_ uint32_t hash() const { return data ? data->hash_cache : 0; }

explicit operator String() const;
bool is_empty() const;
Expand Down