diff --git a/uppsrc/Core/AString.hpp b/uppsrc/Core/AString.hpp index 8caf7d8a6..348a0fba0 100644 --- a/uppsrc/Core/AString.hpp +++ b/uppsrc/Core/AString.hpp @@ -252,7 +252,7 @@ force_inline void String0::Set(const char *s, int len) { Clear(); - if(len < 14) { + if(len <= 14) { memcpy8(chr, s, len); SLen() = len; Dsyn(); @@ -262,9 +262,23 @@ void String0::Set(const char *s, int len) Dsyn(); } +force_inline +void String0::Set0(const char *s, int len) +{ + Zero(); + if(len <= 14) { + SLen() = len; + memcpy8(chr, s, len); + Dsyn(); + return; + } + SetL(s, len); + Dsyn(); +} + inline bool String0::IsEqual(const char *s) const -{ // This optimized for comparison with string literals... +{ // This is optimized for comparison with string literals... size_t len = strlen(s); const void *p; if(IsSmall()) { diff --git a/uppsrc/Core/String.cpp b/uppsrc/Core/String.cpp index 533c6c772..a14484926 100644 --- a/uppsrc/Core/String.cpp +++ b/uppsrc/Core/String.cpp @@ -192,18 +192,6 @@ void String0::SetL(const char *s, int len) SLen() = 15; } -void String0::Set0(const char *s, int len) -{ - Zero(); - if(len <= 14) { - SLen() = len; - memcpy8(chr, s, len); - } - else - SetL(s, len); - Dsyn(); -} - void String::AssignLen(const char *s, int slen) { int len = GetCount(); diff --git a/uppsrc/Core/String.h b/uppsrc/Core/String.h index d0f1383ca..fa38f1871 100644 --- a/uppsrc/Core/String.h +++ b/uppsrc/Core/String.h @@ -336,7 +336,7 @@ public: int GetAlloc() const { return IsSmall() ? 14 : LAlloc(); } void Reserve(int r); - + // String0& operator=(const String0& s) { Free(); Set0(s); return *this; } String0() {} @@ -397,9 +397,13 @@ public: static String GetVoid(); bool IsVoid() const; + + enum SmallHint { SMALL_HINT }; + + String(const char *s, int n, SmallHint) { ASSERT(n <= 14); Zero(); SLen() = n; memcpy8(chr, s, n); Dsyn(); } friend void Swap(String& a, String& b) { a.Swap(b); } - + String(const std::string& s) { String0::Set0(s.c_str(), (int)s.length()); } std::string ToStd() const { return std::string(Begin(), End()); } };