diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2017-03-05 16:44:50 +0100 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2017-03-05 16:44:50 +0100 |
commit | 5dbf1809c6e3e905b94b8764e99491e608122261 (patch) | |
tree | 5e5a5360db15d86d59ec8c6e4f7eb511388c5a9a /core/string_db.cpp | |
parent | 45438e9918d421b244bfd7776a30e67dc7f2d3e3 (diff) |
A Whole New World (clang-format edition)
I can show you the code
Pretty, with proper whitespace
Tell me, coder, now when did
You last write readable code?
I can open your eyes
Make you see your bad indent
Force you to respect the style
The core devs agreed upon
A whole new world
A new fantastic code format
A de facto standard
With some sugar
Enforced with clang-format
A whole new world
A dazzling style we all dreamed of
And when we read it through
It's crystal clear
That now we're in a whole new world of code
Diffstat (limited to 'core/string_db.cpp')
-rw-r--r-- | core/string_db.cpp | 239 |
1 files changed, 106 insertions, 133 deletions
diff --git a/core/string_db.cpp b/core/string_db.cpp index 004b07b9e5..54535fa06b 100644 --- a/core/string_db.cpp +++ b/core/string_db.cpp @@ -28,61 +28,63 @@ /*************************************************************************/ #include "string_db.h" -#include "print_string.h" #include "os/os.h" +#include "print_string.h" StaticCString StaticCString::create(const char *p_ptr) { - StaticCString scs; scs.ptr=p_ptr; return scs; + StaticCString scs; + scs.ptr = p_ptr; + return scs; } StringName::_Data *StringName::_table[STRING_TABLE_LEN]; StringName _scs_create(const char *p_chr) { - return (p_chr[0]?StringName(StaticCString::create(p_chr)):StringName()); + return (p_chr[0] ? StringName(StaticCString::create(p_chr)) : StringName()); } -bool StringName::configured=false; -Mutex* StringName::lock=NULL; +bool StringName::configured = false; +Mutex *StringName::lock = NULL; void StringName::setup() { lock = Mutex::create(); ERR_FAIL_COND(configured); - for(int i=0;i<STRING_TABLE_LEN;i++) { + for (int i = 0; i < STRING_TABLE_LEN; i++) { - _table[i]=NULL; + _table[i] = NULL; } - configured=true; + configured = true; } void StringName::cleanup() { lock->lock(); - int lost_strings=0; - for(int i=0;i<STRING_TABLE_LEN;i++) { + int lost_strings = 0; + for (int i = 0; i < STRING_TABLE_LEN; i++) { - while(_table[i]) { + while (_table[i]) { - _Data*d=_table[i]; + _Data *d = _table[i]; lost_strings++; if (OS::get_singleton()->is_stdout_verbose()) { if (d->cname) { - print_line("Orphan StringName: "+String(d->cname)); + print_line("Orphan StringName: " + String(d->cname)); } else { - print_line("Orphan StringName: "+String(d->name)); + print_line("Orphan StringName: " + String(d->name)); } } - _table[i]=_table[i]->next; + _table[i] = _table[i]->next; memdelete(d); } } if (OS::get_singleton()->is_stdout_verbose() && lost_strings) { - print_line("StringName: "+itos(lost_strings)+" unclaimed string names at exit."); + print_line("StringName: " + itos(lost_strings) + " unclaimed string names at exit."); } lock->unlock(); @@ -98,65 +100,59 @@ void StringName::unref() { lock->lock(); if (_data->prev) { - _data->prev->next=_data->next; + _data->prev->next = _data->next; } else { - if (_table[_data->idx]!=_data) { + if (_table[_data->idx] != _data) { ERR_PRINT("BUG!"); } - _table[_data->idx]=_data->next; + _table[_data->idx] = _data->next; } if (_data->next) { - _data->next->prev=_data->prev; - + _data->next->prev = _data->prev; } memdelete(_data); lock->unlock(); } - _data=NULL; - + _data = NULL; } -bool StringName::operator==(const String& p_name) const { +bool StringName::operator==(const String &p_name) const { if (!_data) { - return (p_name.length()==0); + return (p_name.length() == 0); } - return (_data->get_name()==p_name); + return (_data->get_name() == p_name); } -bool StringName::operator==(const char* p_name) const { +bool StringName::operator==(const char *p_name) const { if (!_data) { - return (p_name[0]==0); + return (p_name[0] == 0); } - return (_data->get_name()==p_name); + return (_data->get_name() == p_name); } -bool StringName::operator!=(const String& p_name) const { +bool StringName::operator!=(const String &p_name) const { return !(operator==(p_name)); } - - -bool StringName::operator!=(const StringName& p_name) const { +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; - + return _data != p_name._data; } +void StringName::operator=(const StringName &p_name) { -void StringName::operator=(const StringName& p_name) { - - if (this==&p_name) + if (this == &p_name) return; unref(); @@ -175,10 +171,10 @@ StringName::operator String() const { return ""; } */ -StringName::StringName(const StringName& p_name) { +StringName::StringName(const StringName &p_name) { ERR_FAIL_COND(!configured); - _data=NULL; + _data = NULL; if (p_name._data && p_name._data->refcount.ref()) { _data = p_name._data; @@ -187,168 +183,154 @@ StringName::StringName(const StringName& p_name) { StringName::StringName(const char *p_name) { - _data=NULL; + _data = NULL; ERR_FAIL_COND(!configured); - if (!p_name || p_name[0]==0) + if (!p_name || p_name[0] == 0) return; //empty, ignore lock->lock(); uint32_t hash = String::hash(p_name); - uint32_t idx=hash&STRING_TABLE_MASK; + uint32_t idx = hash & STRING_TABLE_MASK; - _data=_table[idx]; + _data = _table[idx]; - while(_data) { + 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; + _data = _data->next; } - if (_data) { if (_data->refcount.ref()) { // exists lock->unlock(); return; } else { - } } - _data = memnew( _Data ); - _data->name=p_name; + _data = memnew(_Data); + _data->name = p_name; _data->refcount.init(); - _data->hash=hash; - _data->idx=idx; - _data->cname=NULL; - _data->next=_table[idx]; - _data->prev=NULL; + _data->hash = hash; + _data->idx = idx; + _data->cname = NULL; + _data->next = _table[idx]; + _data->prev = NULL; if (_table[idx]) - _table[idx]->prev=_data; - _table[idx]=_data; - + _table[idx]->prev = _data; + _table[idx] = _data; lock->unlock(); } -StringName::StringName(const StaticCString& p_static_string) { +StringName::StringName(const StaticCString &p_static_string) { - _data=NULL; + _data = NULL; ERR_FAIL_COND(!configured); - ERR_FAIL_COND( !p_static_string.ptr || !p_static_string.ptr[0]); + ERR_FAIL_COND(!p_static_string.ptr || !p_static_string.ptr[0]); lock->lock(); uint32_t hash = String::hash(p_static_string.ptr); - uint32_t idx=hash&STRING_TABLE_MASK; + uint32_t idx = hash & STRING_TABLE_MASK; - _data=_table[idx]; + _data = _table[idx]; - while(_data) { + 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; + _data = _data->next; } - if (_data) { if (_data->refcount.ref()) { // exists lock->unlock(); return; } else { - } } - _data = memnew( _Data ); + _data = memnew(_Data); _data->refcount.init(); - _data->hash=hash; - _data->idx=idx; - _data->cname=p_static_string.ptr; - _data->next=_table[idx]; - _data->prev=NULL; + _data->hash = hash; + _data->idx = idx; + _data->cname = p_static_string.ptr; + _data->next = _table[idx]; + _data->prev = NULL; if (_table[idx]) - _table[idx]->prev=_data; - _table[idx]=_data; - + _table[idx]->prev = _data; + _table[idx] = _data; lock->unlock(); - - } +StringName::StringName(const String &p_name) { -StringName::StringName(const String& p_name) { - - _data=NULL; + _data = NULL; ERR_FAIL_COND(!configured); - if (p_name==String()) + if (p_name == String()) return; lock->lock(); uint32_t hash = p_name.hash(); - uint32_t idx=hash&STRING_TABLE_MASK; + uint32_t idx = hash & STRING_TABLE_MASK; - _data=_table[idx]; + _data = _table[idx]; - while(_data) { + while (_data) { - if (_data->hash==hash && _data->get_name()==p_name) + if (_data->hash == hash && _data->get_name() == p_name) break; - _data=_data->next; + _data = _data->next; } - if (_data) { if (_data->refcount.ref()) { // exists lock->unlock(); return; } else { - - } } - - _data = memnew( _Data ); - _data->name=p_name; + _data = memnew(_Data); + _data->name = p_name; _data->refcount.init(); - _data->hash=hash; - _data->idx=idx; - _data->cname=NULL; - _data->next=_table[idx]; - _data->prev=NULL; + _data->hash = hash; + _data->idx = idx; + _data->cname = NULL; + _data->next = _table[idx]; + _data->prev = NULL; if (_table[idx]) - _table[idx]->prev=_data; - _table[idx]=_data; + _table[idx]->prev = _data; + _table[idx] = _data; lock->unlock(); - } StringName StringName::search(const char *p_name) { - ERR_FAIL_COND_V(!configured,StringName()); + ERR_FAIL_COND_V(!configured, StringName()); - ERR_FAIL_COND_V( !p_name, StringName() ); + ERR_FAIL_COND_V(!p_name, StringName()); if (!p_name[0]) return StringName(); @@ -356,36 +338,33 @@ StringName StringName::search(const char *p_name) { uint32_t hash = String::hash(p_name); - uint32_t idx=hash&STRING_TABLE_MASK; + uint32_t idx = hash & STRING_TABLE_MASK; - _Data *_data=_table[idx]; + _Data *_data = _table[idx]; - while(_data) { + 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; + _data = _data->next; } if (_data && _data->refcount.ref()) { lock->unlock(); return StringName(_data); - } lock->unlock(); return StringName(); //does not exist - - } StringName StringName::search(const CharType *p_name) { - ERR_FAIL_COND_V(!configured,StringName()); + ERR_FAIL_COND_V(!configured, StringName()); - ERR_FAIL_COND_V( !p_name, StringName() ); + ERR_FAIL_COND_V(!p_name, StringName()); if (!p_name[0]) return StringName(); @@ -393,67 +372,61 @@ StringName StringName::search(const CharType *p_name) { uint32_t hash = String::hash(p_name); - uint32_t idx=hash&STRING_TABLE_MASK; + uint32_t idx = hash & STRING_TABLE_MASK; - _Data *_data=_table[idx]; + _Data *_data = _table[idx]; - while(_data) { + 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; + _data = _data->next; } if (_data && _data->refcount.ref()) { lock->unlock(); return StringName(_data); - } lock->unlock(); return StringName(); //does not exist - } StringName StringName::search(const String &p_name) { - ERR_FAIL_COND_V( p_name=="", StringName() ); + ERR_FAIL_COND_V(p_name == "", StringName()); lock->lock(); uint32_t hash = p_name.hash(); - uint32_t idx=hash&STRING_TABLE_MASK; + uint32_t idx = hash & STRING_TABLE_MASK; - _Data *_data=_table[idx]; + _Data *_data = _table[idx]; - while(_data) { + 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; + _data = _data->next; } if (_data && _data->refcount.ref()) { lock->unlock(); return StringName(_data); - } lock->unlock(); return StringName(); //does not exist - } - StringName::StringName() { - _data=NULL; + _data = NULL; } StringName::~StringName() { unref(); } - |