Skip to content

Commit 82e73f5

Browse files
committed
Merge pull request godotengine#115473 from Ivorforce/nodepath-hash
Fix the `NodePath` hash function to not yield the same value for similar paths
2 parents dfc8705 + 7f5725f commit 82e73f5

1 file changed

Lines changed: 4 additions & 13 deletions

File tree

core/string/node_path.cpp

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,11 @@
3333
#include "core/variant/variant.h"
3434

3535
void NodePath::_update_hash_cache() const {
36-
uint32_t h = data->absolute ? 1 : 0;
37-
int pc = data->path.size();
38-
const StringName *sn = data->path.ptr();
39-
for (int i = 0; i < pc; i++) {
40-
h = h ^ sn[i].hash();
41-
}
42-
int spc = data->subpath.size();
43-
const StringName *ssn = data->subpath.ptr();
44-
for (int i = 0; i < spc; i++) {
45-
h = h ^ ssn[i].hash();
46-
}
47-
36+
StringName path = get_concatenated_names();
37+
StringName subpath = get_concatenated_subnames();
38+
uint32_t hash = HashMapHasherDefault::hash(Pair<const StringName &, const StringName &>(path, subpath));
39+
data->hash_cache = is_absolute() ? hash : ~hash;
4840
data->hash_cache_valid = true;
49-
data->hash_cache = h;
5041
}
5142

5243
void NodePath::prepend_period() {

0 commit comments

Comments
 (0)