Core: Minor StringBuffer optimisation

git-svn-id: svn://ultimatepp.org/upp/trunk@14891 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2020-08-24 15:10:42 +00:00
parent f8eeea5a6b
commit 09f2a25251
3 changed files with 23 additions and 15 deletions

View file

@ -288,6 +288,26 @@ void StringBuffer::Strlen()
SetLength((int)strlen__(pbegin));
}
inline
void StringBuffer::Cat(const char *s, int l)
{
if(pend + l > limit)
ReallocL(s, l);
else {
memcpy8(pend, s, l);
pend += l;
}
}
inline
void StringBuffer::Cat(int c, int l)
{
if(pend + l > limit)
ReallocL(NULL, l);
memset8(pend, c, l);
pend += l;
}
force_inline
void StringBuffer::Cat(const char *s)
{

View file

@ -416,22 +416,9 @@ void StringBuffer::Shrink()
pend = pbegin + l;
}
void StringBuffer::Cat(const char *s, int l)
void StringBuffer::ReallocL(const char *s, int l)
{
if(pend + l > limit)
Realloc(max(GetLength(), l) + GetLength(), s, l);
else {
memcpy8(pend, s, l);
pend += l;
}
}
void StringBuffer::Cat(int c, int l)
{
if(pend + l > limit)
Realloc(max(GetLength(), l) + GetLength(), NULL, l);
memset(pend, c, l);
pend += l;
Realloc(max(GetLength(), l) + GetLength(), s, l);
}
void StringBuffer::Set(String& s)

View file

@ -408,6 +408,7 @@ class StringBuffer : NoCopy {
char *Alloc(int len, int& alloc);
void Realloc(dword n, const char *cat = NULL, int l = 0);
void ReallocL(const char *s, int l);
void Expand();
void Zero() { pbegin = pend = buffer; limit = pbegin + 255; }
void Free();