Core: String small hint constructor variant

git-svn-id: svn://ultimatepp.org/upp/trunk@16014 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2021-07-07 14:20:14 +00:00
parent 688147651b
commit 8a186a089e
3 changed files with 22 additions and 16 deletions

View file

@ -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()) {

View file

@ -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();

View file

@ -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()); }
};