3333#include " core/os/os.h"
3434#include " core/string/print_string.h"
3535
36- StaticCString StaticCString::create (const char *p_ptr) {
37- StaticCString scs;
38- scs.ptr = p_ptr;
39- return scs;
40- }
41-
4236bool StringName::_Data::operator ==(const String &p_name) const {
43- if (cname) {
44- return p_name == cname;
45- } else {
46- return name == p_name;
47- }
37+ return name == p_name;
4838}
4939
5040bool StringName::_Data::operator !=(const String &p_name) const {
5141 return !operator ==(p_name);
5242}
5343
5444bool StringName::_Data::operator ==(const char *p_name) const {
55- if (cname) {
56- return strcmp (cname, p_name) == 0 ;
57- } else {
58- return name == p_name;
59- }
45+ return name == p_name;
6046}
6147
6248bool StringName::_Data::operator !=(const char *p_name) const {
6349 return !operator ==(p_name);
6450}
6551
66- StringName _scs_create (const char *p_chr, bool p_static) {
67- return (p_chr[0 ] ? StringName (StaticCString::create (p_chr), p_static) : StringName ());
68- }
69-
7052void StringName::setup () {
7153 ERR_FAIL_COND (configured);
7254 for (int i = 0 ; i < STRING_TABLE_LEN; i++) {
@@ -115,9 +97,7 @@ void StringName::cleanup() {
11597 lost_strings++;
11698
11799 if (OS::get_singleton ()->is_stdout_verbose ()) {
118- String dname = String (d->cname ? d->cname : d->name );
119-
120- print_line (vformat (" Orphan StringName: %s (static: %d, total: %d)" , dname, d->static_count .get (), d->refcount .get ()));
100+ print_line (vformat (" Orphan StringName: %s (static: %d, total: %d)" , d->name , d->static_count .get (), d->refcount .get ()));
121101 }
122102 }
123103
@@ -138,11 +118,7 @@ void StringName::unref() {
138118 MutexLock lock (mutex);
139119
140120 if (CoreGlobals::leak_reporting_enabled && _data->static_count .get () > 0 ) {
141- if (_data->cname ) {
142- ERR_PRINT (" BUG: Unreferenced static string to 0: " + String (_data->cname ));
143- } else {
144- ERR_PRINT (" BUG: Unreferenced static string to 0: " + String (_data->name ));
145- }
121+ ERR_PRINT (" BUG: Unreferenced static string to 0: " + _data->name );
146122 }
147123 if (_data->prev ) {
148124 _data->prev ->next = _data->next ;
@@ -193,12 +169,7 @@ bool StringName::operator!=(const char *p_name) const {
193169
194170char32_t StringName::operator [](int p_index) const {
195171 if (_data) {
196- if (_data->cname ) {
197- CRASH_BAD_INDEX (p_index, static_cast <long >(strlen (_data->cname )));
198- return _data->cname [p_index];
199- } else {
200- return _data->name [p_index];
201- }
172+ return _data->name [p_index];
202173 }
203174
204175 CRASH_BAD_INDEX (p_index, 0 );
@@ -207,23 +178,15 @@ char32_t StringName::operator[](int p_index) const {
207178
208179int StringName::length () const {
209180 if (_data) {
210- if (_data->cname ) {
211- return strlen (_data->cname );
212- } else {
213- return _data->name .length ();
214- }
181+ return _data->name .length ();
215182 }
216183
217184 return 0 ;
218185}
219186
220187bool StringName::is_empty () const {
221188 if (_data) {
222- if (_data->cname ) {
223- return _data->cname [0 ] == 0 ;
224- } else {
225- return _data->name .is_empty ();
226- }
189+ return _data->name .is_empty ();
227190 }
228191
229192 return true ;
@@ -302,7 +265,6 @@ StringName::StringName(const char *p_name, bool p_static) {
302265 _data->static_count .set (p_static ? 1 : 0 );
303266 _data->hash = hash;
304267 _data->idx = idx;
305- _data->cname = nullptr ;
306268 _data->next = _table[idx];
307269 _data->prev = nullptr ;
308270
@@ -319,62 +281,6 @@ StringName::StringName(const char *p_name, bool p_static) {
319281 _table[idx] = _data;
320282}
321283
322- StringName::StringName (const StaticCString &p_static_string, bool p_static) {
323- _data = nullptr ;
324-
325- ERR_FAIL_COND (!configured);
326-
327- ERR_FAIL_COND (!p_static_string.ptr || !p_static_string.ptr [0 ]);
328-
329- const uint32_t hash = String::hash (p_static_string.ptr );
330- const uint32_t idx = hash & STRING_TABLE_MASK;
331-
332- MutexLock lock (mutex);
333- _data = _table[idx];
334-
335- while (_data) {
336- // compare hash first
337- if (_data->hash == hash && _data->operator ==(p_static_string.ptr )) {
338- break ;
339- }
340- _data = _data->next ;
341- }
342-
343- if (_data && _data->refcount .ref ()) {
344- // exists
345- if (p_static) {
346- _data->static_count .increment ();
347- }
348- #ifdef DEBUG_ENABLED
349- if (unlikely (debug_stringname)) {
350- _data->debug_references ++;
351- }
352- #endif
353- return ;
354- }
355-
356- _data = memnew (_Data);
357-
358- _data->refcount .init ();
359- _data->static_count .set (p_static ? 1 : 0 );
360- _data->hash = hash;
361- _data->idx = idx;
362- _data->cname = p_static_string.ptr ;
363- _data->next = _table[idx];
364- _data->prev = nullptr ;
365- #ifdef DEBUG_ENABLED
366- if (unlikely (debug_stringname)) {
367- // Keep in memory, force static.
368- _data->refcount .ref ();
369- _data->static_count .increment ();
370- }
371- #endif
372- if (_table[idx]) {
373- _table[idx]->prev = _data;
374- }
375- _table[idx] = _data;
376- }
377-
378284StringName::StringName (const String &p_name, bool p_static) {
379285 _data = nullptr ;
380286
@@ -416,7 +322,6 @@ StringName::StringName(const String &p_name, bool p_static) {
416322 _data->static_count .set (p_static ? 1 : 0 );
417323 _data->hash = hash;
418324 _data->idx = idx;
419- _data->cname = nullptr ;
420325 _data->next = _table[idx];
421326 _data->prev = nullptr ;
422327#ifdef DEBUG_ENABLED
0 commit comments