summaryrefslogtreecommitdiff
path: root/core/string_name.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/string_name.cpp')
-rw-r--r--core/string_name.cpp72
1 files changed, 29 insertions, 43 deletions
diff --git a/core/string_name.cpp b/core/string_name.cpp
index bfc10d96e4..cbf6009681 100644
--- a/core/string_name.cpp
+++ b/core/string_name.cpp
@@ -42,7 +42,6 @@ StaticCString StaticCString::create(const char *p_ptr) {
StringName::_Data *StringName::_table[STRING_TABLE_LEN];
StringName _scs_create(const char *p_chr) {
-
return (p_chr[0] ? StringName(StaticCString::create(p_chr)) : StringName());
}
@@ -50,24 +49,19 @@ bool StringName::configured = false;
Mutex StringName::mutex;
void StringName::setup() {
-
ERR_FAIL_COND(configured);
for (int i = 0; i < STRING_TABLE_LEN; i++) {
-
_table[i] = nullptr;
}
configured = true;
}
void StringName::cleanup() {
-
MutexLock lock(mutex);
int lost_strings = 0;
for (int i = 0; i < STRING_TABLE_LEN; i++) {
-
while (_table[i]) {
-
_Data *d = _table[i];
lost_strings++;
if (OS::get_singleton()->is_stdout_verbose()) {
@@ -88,11 +82,9 @@ void StringName::cleanup() {
}
void StringName::unref() {
-
ERR_FAIL_COND(!configured);
if (_data && _data->refcount.unref()) {
-
MutexLock lock(mutex);
if (_data->prev) {
@@ -114,9 +106,7 @@ void StringName::unref() {
}
bool StringName::operator==(const String &p_name) const {
-
if (!_data) {
-
return (p_name.length() == 0);
}
@@ -124,9 +114,7 @@ bool StringName::operator==(const String &p_name) const {
}
bool StringName::operator==(const char *p_name) const {
-
if (!_data) {
-
return (p_name[0] == 0);
}
@@ -134,32 +122,28 @@ bool StringName::operator==(const char *p_name) const {
}
bool StringName::operator!=(const String &p_name) const {
-
return !(operator==(p_name));
}
bool StringName::operator!=(const StringName &p_name) const {
-
// the real magic of all this mess happens here.
// this is why path comparisons are very fast
return _data != p_name._data;
}
void StringName::operator=(const StringName &p_name) {
-
- if (this == &p_name)
+ if (this == &p_name) {
return;
+ }
unref();
if (p_name._data && p_name._data->refcount.ref()) {
-
_data = p_name._data;
}
}
StringName::StringName(const StringName &p_name) {
-
_data = nullptr;
ERR_FAIL_COND(!configured);
@@ -170,13 +154,13 @@ StringName::StringName(const StringName &p_name) {
}
StringName::StringName(const char *p_name) {
-
_data = nullptr;
ERR_FAIL_COND(!configured);
- if (!p_name || p_name[0] == 0)
+ if (!p_name || p_name[0] == 0) {
return; //empty, ignore
+ }
MutexLock lock(mutex);
@@ -187,10 +171,10 @@ StringName::StringName(const char *p_name) {
_data = _table[idx];
while (_data) {
-
// compare hash first
- if (_data->hash == hash && _data->get_name() == p_name)
+ if (_data->hash == hash && _data->get_name() == p_name) {
break;
+ }
_data = _data->next;
}
@@ -209,13 +193,13 @@ StringName::StringName(const char *p_name) {
_data->cname = nullptr;
_data->next = _table[idx];
_data->prev = nullptr;
- if (_table[idx])
+ if (_table[idx]) {
_table[idx]->prev = _data;
+ }
_table[idx] = _data;
}
StringName::StringName(const StaticCString &p_static_string) {
-
_data = nullptr;
ERR_FAIL_COND(!configured);
@@ -231,10 +215,10 @@ StringName::StringName(const StaticCString &p_static_string) {
_data = _table[idx];
while (_data) {
-
// compare hash first
- if (_data->hash == hash && _data->get_name() == p_static_string.ptr)
+ if (_data->hash == hash && _data->get_name() == p_static_string.ptr) {
break;
+ }
_data = _data->next;
}
@@ -253,19 +237,20 @@ StringName::StringName(const StaticCString &p_static_string) {
_data->cname = p_static_string.ptr;
_data->next = _table[idx];
_data->prev = nullptr;
- if (_table[idx])
+ if (_table[idx]) {
_table[idx]->prev = _data;
+ }
_table[idx] = _data;
}
StringName::StringName(const String &p_name) {
-
_data = nullptr;
ERR_FAIL_COND(!configured);
- if (p_name == String())
+ if (p_name == String()) {
return;
+ }
MutexLock lock(mutex);
@@ -275,9 +260,9 @@ StringName::StringName(const String &p_name) {
_data = _table[idx];
while (_data) {
-
- if (_data->hash == hash && _data->get_name() == p_name)
+ if (_data->hash == hash && _data->get_name() == p_name) {
break;
+ }
_data = _data->next;
}
@@ -296,18 +281,19 @@ StringName::StringName(const String &p_name) {
_data->cname = nullptr;
_data->next = _table[idx];
_data->prev = nullptr;
- if (_table[idx])
+ if (_table[idx]) {
_table[idx]->prev = _data;
+ }
_table[idx] = _data;
}
StringName StringName::search(const char *p_name) {
-
ERR_FAIL_COND_V(!configured, StringName());
ERR_FAIL_COND_V(!p_name, StringName());
- if (!p_name[0])
+ if (!p_name[0]) {
return StringName();
+ }
MutexLock lock(mutex);
@@ -317,10 +303,10 @@ StringName StringName::search(const char *p_name) {
_Data *_data = _table[idx];
while (_data) {
-
// compare hash first
- if (_data->hash == hash && _data->get_name() == p_name)
+ if (_data->hash == hash && _data->get_name() == p_name) {
break;
+ }
_data = _data->next;
}
@@ -332,12 +318,12 @@ StringName StringName::search(const char *p_name) {
}
StringName StringName::search(const CharType *p_name) {
-
ERR_FAIL_COND_V(!configured, StringName());
ERR_FAIL_COND_V(!p_name, StringName());
- if (!p_name[0])
+ if (!p_name[0]) {
return StringName();
+ }
MutexLock lock(mutex);
@@ -348,10 +334,10 @@ StringName StringName::search(const CharType *p_name) {
_Data *_data = _table[idx];
while (_data) {
-
// compare hash first
- if (_data->hash == hash && _data->get_name() == p_name)
+ if (_data->hash == hash && _data->get_name() == p_name) {
break;
+ }
_data = _data->next;
}
@@ -361,8 +347,8 @@ StringName StringName::search(const CharType *p_name) {
return StringName(); //does not exist
}
-StringName StringName::search(const String &p_name) {
+StringName StringName::search(const String &p_name) {
ERR_FAIL_COND_V(p_name == "", StringName());
MutexLock lock(mutex);
@@ -374,10 +360,10 @@ StringName StringName::search(const String &p_name) {
_Data *_data = _table[idx];
while (_data) {
-
// compare hash first
- if (_data->hash == hash && p_name == _data->get_name())
+ if (_data->hash == hash && p_name == _data->get_name()) {
break;
+ }
_data = _data->next;
}