From 09f2a25251b4038d9e2cffd37fb2c53ce132b026 Mon Sep 17 00:00:00 2001 From: cxl Date: Mon, 24 Aug 2020 15:10:42 +0000 Subject: [PATCH] Core: Minor StringBuffer optimisation git-svn-id: svn://ultimatepp.org/upp/trunk@14891 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/Core/AString.hpp | 20 ++++++++++++++++++++ uppsrc/Core/String.cpp | 17 ++--------------- uppsrc/Core/String.h | 1 + 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/uppsrc/Core/AString.hpp b/uppsrc/Core/AString.hpp index 75d04698d..98e0422a0 100644 --- a/uppsrc/Core/AString.hpp +++ b/uppsrc/Core/AString.hpp @@ -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) { diff --git a/uppsrc/Core/String.cpp b/uppsrc/Core/String.cpp index f852b7ee0..30d7caa2d 100644 --- a/uppsrc/Core/String.cpp +++ b/uppsrc/Core/String.cpp @@ -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) diff --git a/uppsrc/Core/String.h b/uppsrc/Core/String.h index 8e5a4df9c..5caaa2961 100644 --- a/uppsrc/Core/String.h +++ b/uppsrc/Core/String.h @@ -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();