Small cleanups and fixes to StringName. Also increased it's internal table's size.

This commit is contained in:
Relintai 2022-08-22 01:44:53 +02:00
parent ae19991c63
commit 45bec656d5
2 changed files with 12 additions and 4 deletions

View File

@ -118,6 +118,8 @@ void StringName::cleanup() {
print_verbose("StringName: " + itos(lost_strings) + " unclaimed string names at exit."); print_verbose("StringName: " + itos(lost_strings) + " unclaimed string names at exit.");
} }
configured = false;
lock.unlock(); lock.unlock();
} }

View File

@ -41,8 +41,7 @@ struct StaticCString {
class StringName { class StringName {
enum { enum {
STRING_TABLE_BITS = 14,
STRING_TABLE_BITS = 12,
STRING_TABLE_LEN = 1 << STRING_TABLE_BITS, STRING_TABLE_LEN = 1 << STRING_TABLE_BITS,
STRING_TABLE_MASK = STRING_TABLE_LEN - 1 STRING_TABLE_MASK = STRING_TABLE_LEN - 1
}; };
@ -60,16 +59,19 @@ class StringName {
String get_name() const { String get_name() const {
return cname ? String(cname) : name; return cname ? String(cname) : name;
} }
int idx; int idx;
uint32_t hash; uint32_t hash;
_Data *prev; _Data *prev;
_Data *next; _Data *next;
_Data() { _Data() {
#ifdef DEBUG_ENABLED #ifdef DEBUG_ENABLED
debug_references = 0; debug_references = 0;
#endif #endif
cname = nullptr; cname = nullptr;
next = prev = nullptr; prev = nullptr;
next = nullptr;
idx = 0; idx = 0;
hash = 0; hash = 0;
} }
@ -82,6 +84,10 @@ class StringName {
union _HashUnion { union _HashUnion {
_Data *ptr; _Data *ptr;
uint32_t hash; uint32_t hash;
_HashUnion() {
ptr = nullptr;
}
}; };
void unref(); void unref();
@ -119,6 +125,7 @@ public:
if (!_data) { if (!_data) {
return false; return false;
} }
if (_data->cname != nullptr) { if (_data->cname != nullptr) {
return _data->cname[0] == '%'; return _data->cname[0] == '%';
} else { } else {
@ -219,5 +226,4 @@ StringName _scs_create(const char *p_chr, bool p_static = false);
//#define SNAME(m_arg) ([]() -> const StringName & { static StringName sname = _scs_create(m_arg, true); return sname; })() //#define SNAME(m_arg) ([]() -> const StringName & { static StringName sname = _scs_create(m_arg, true); return sname; })()
#endif // STRING_NAME_H #endif // STRING_NAME_H