mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2024-11-10 14:51:46 +00:00
Reduced code duplication in FString class
Moved resetting of string data to null value into own function
This commit is contained in:
parent
3cefe10818
commit
7d97963005
2 changed files with 12 additions and 11 deletions
|
@ -66,8 +66,7 @@ FString::FString (const char *copyStr)
|
|||
{
|
||||
if (copyStr == NULL || *copyStr == '\0')
|
||||
{
|
||||
NullString.RefCount++;
|
||||
Chars = &NullString.Nothing[0];
|
||||
ResetToNull();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -87,8 +86,7 @@ FString::FString (char oneChar)
|
|||
{
|
||||
if (oneChar == '\0')
|
||||
{
|
||||
NullString.RefCount++;
|
||||
Chars = &NullString.Nothing[0];
|
||||
ResetToNull();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -220,8 +218,7 @@ FString &FString::operator = (const char *copyStr)
|
|||
if (copyStr == NULL || *copyStr == '\0')
|
||||
{
|
||||
Data()->Release();
|
||||
NullString.RefCount++;
|
||||
Chars = &NullString.Nothing[0];
|
||||
ResetToNull();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -362,8 +359,7 @@ FString &FString::CopyCStrPart(const char *tail, size_t tailLen)
|
|||
else
|
||||
{
|
||||
Data()->Release();
|
||||
NullString.RefCount++;
|
||||
Chars = &NullString.Nothing[0];
|
||||
ResetToNull();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
@ -373,8 +369,7 @@ void FString::Truncate(size_t newlen)
|
|||
if (newlen == 0)
|
||||
{
|
||||
Data()->Release();
|
||||
NullString.RefCount++;
|
||||
Chars = &NullString.Nothing[0];
|
||||
ResetToNull();
|
||||
}
|
||||
else if (newlen < Len())
|
||||
{
|
||||
|
|
|
@ -120,7 +120,7 @@ enum ELumpNum
|
|||
class FString
|
||||
{
|
||||
public:
|
||||
FString () : Chars(&NullString.Nothing[0]) { NullString.RefCount++; }
|
||||
FString () { ResetToNull(); }
|
||||
|
||||
// Copy constructors
|
||||
FString (const FString &other) { AttachToOther (other); }
|
||||
|
@ -311,6 +311,12 @@ protected:
|
|||
const FStringData *Data() const { return (FStringData *)Chars - 1; }
|
||||
FStringData *Data() { return (FStringData *)Chars - 1; }
|
||||
|
||||
void ResetToNull()
|
||||
{
|
||||
NullString.RefCount++;
|
||||
Chars = &NullString.Nothing[0];
|
||||
}
|
||||
|
||||
void AttachToOther (const FString &other);
|
||||
void AllocBuffer (size_t len);
|
||||
void ReallocBuffer (size_t newlen);
|
||||
|
|
Loading…
Reference in a new issue