From f064a415b3d51667b224c144473ddccf0a4b0578 Mon Sep 17 00:00:00 2001 From: Lukas Tenbrink Date: Fri, 25 Apr 2025 19:19:03 +0200 Subject: [PATCH] Use `PagedAllocator` for `StringName` to accelerate and localize allocations. --- core/string/string_name.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/core/string/string_name.cpp b/core/string/string_name.cpp index de462cf402..ecf9cfc33c 100644 --- a/core/string/string_name.cpp +++ b/core/string/string_name.cpp @@ -40,6 +40,7 @@ struct StringName::Table { static inline _Data *table[TABLE_LEN]; static inline Mutex mutex; + static inline PagedAllocator<_Data> allocator; }; void StringName::setup() { @@ -95,7 +96,7 @@ void StringName::cleanup() { } Table::table[i] = Table::table[i]->next; - memdelete(d); + Table::allocator.free(d); } } if (lost_strings) { @@ -123,7 +124,7 @@ void StringName::unref() { if (_data->next) { _data->next->prev = _data->prev; } - memdelete(_data); + Table::allocator.free(_data); } _data = nullptr; @@ -250,7 +251,7 @@ StringName::StringName(const char *p_name, bool p_static) { return; } - _data = memnew(_Data); + _data = Table::allocator.alloc(); _data->name = p_name; _data->refcount.init(); _data->static_count.set(p_static ? 1 : 0); @@ -306,7 +307,7 @@ StringName::StringName(const String &p_name, bool p_static) { return; } - _data = memnew(_Data); + _data = Table::allocator.alloc(); _data->name = p_name; _data->refcount.init(); _data->static_count.set(p_static ? 1 : 0);