Fix the NodePath hash function to not yield the same value for similar paths.

(cherry picked from commit a6e952c1604963023a87c07093cc9b24e6d6591d)
This commit is contained in:
Lukas Tenbrink
2026-01-27 20:50:10 +01:00
committed by Thaddeus Crews
parent 5222598c11
commit 1f6f4b622e

View File

@@ -33,20 +33,11 @@
#include "core/variant/variant.h" #include "core/variant/variant.h"
void NodePath::_update_hash_cache() const { void NodePath::_update_hash_cache() const {
uint32_t h = data->absolute ? 1 : 0; StringName path = get_concatenated_names();
int pc = data->path.size(); StringName subpath = get_concatenated_subnames();
const StringName *sn = data->path.ptr(); uint32_t hash = HashMapHasherDefault::hash(Pair<const StringName &, const StringName &>(path, subpath));
for (int i = 0; i < pc; i++) { data->hash_cache = is_absolute() ? hash : ~hash;
h = h ^ sn[i].hash();
}
int spc = data->subpath.size();
const StringName *ssn = data->subpath.ptr();
for (int i = 0; i < spc; i++) {
h = h ^ ssn[i].hash();
}
data->hash_cache_valid = true; data->hash_cache_valid = true;
data->hash_cache = h;
} }
void NodePath::prepend_period() { void NodePath::prepend_period() {