Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lock the StringName::mutex after hashing the string, to spend less time hoarding it unnecessarily. #101606

Merged
merged 1 commit into from
Jan 16, 2025
Merged
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
46 changes: 18 additions & 28 deletions core/string/string_name.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,12 +269,10 @@ StringName::StringName(const char *p_name, bool p_static) {
return; //empty, ignore
}

MutexLock lock(mutex);

uint32_t hash = String::hash(p_name);

uint32_t idx = hash & STRING_TABLE_MASK;
const uint32_t hash = String::hash(p_name);
const uint32_t idx = hash & STRING_TABLE_MASK;

MutexLock lock(mutex);
_data = _table[idx];

while (_data) {
Expand Down Expand Up @@ -328,12 +326,10 @@ StringName::StringName(const StaticCString &p_static_string, bool p_static) {

ERR_FAIL_COND(!p_static_string.ptr || !p_static_string.ptr[0]);

MutexLock lock(mutex);

uint32_t hash = String::hash(p_static_string.ptr);

uint32_t idx = hash & STRING_TABLE_MASK;
const uint32_t hash = String::hash(p_static_string.ptr);
const uint32_t idx = hash & STRING_TABLE_MASK;

MutexLock lock(mutex);
_data = _table[idx];

while (_data) {
Expand Down Expand Up @@ -388,11 +384,10 @@ StringName::StringName(const String &p_name, bool p_static) {
return;
}

MutexLock lock(mutex);

uint32_t hash = p_name.hash();
uint32_t idx = hash & STRING_TABLE_MASK;
const uint32_t hash = p_name.hash();
const uint32_t idx = hash & STRING_TABLE_MASK;

MutexLock lock(mutex);
_data = _table[idx];

while (_data) {
Expand Down Expand Up @@ -446,11 +441,10 @@ StringName StringName::search(const char *p_name) {
return StringName();
}

MutexLock lock(mutex);

uint32_t hash = String::hash(p_name);
uint32_t idx = hash & STRING_TABLE_MASK;
const uint32_t hash = String::hash(p_name);
const uint32_t idx = hash & STRING_TABLE_MASK;

MutexLock lock(mutex);
_Data *_data = _table[idx];

while (_data) {
Expand Down Expand Up @@ -482,12 +476,10 @@ StringName StringName::search(const char32_t *p_name) {
return StringName();
}

MutexLock lock(mutex);

uint32_t hash = String::hash(p_name);

uint32_t idx = hash & STRING_TABLE_MASK;
const uint32_t hash = String::hash(p_name);
const uint32_t idx = hash & STRING_TABLE_MASK;

MutexLock lock(mutex);
_Data *_data = _table[idx];

while (_data) {
Expand All @@ -508,12 +500,10 @@ StringName StringName::search(const char32_t *p_name) {
StringName StringName::search(const String &p_name) {
ERR_FAIL_COND_V(p_name.is_empty(), StringName());

MutexLock lock(mutex);

uint32_t hash = p_name.hash();

uint32_t idx = hash & STRING_TABLE_MASK;
const uint32_t hash = p_name.hash();
const uint32_t idx = hash & STRING_TABLE_MASK;

MutexLock lock(mutex);
_Data *_data = _table[idx];

while (_data) {
Expand Down