size some stringbuffer to prevent re-alloc
I started with 32 and kept doubling the size until the site did not need re-alloc, but clamped it at 512 (e.g. in emfio/). Change-Id: Ib7caf35a1b7e42b0e4ed8aa812493449e3eefc8f Reviewed-on: https://gerrit.libreoffice.org/81540 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
committed by
Noel Grandin
parent
d04f044f05
commit
e276c81264
@@ -722,7 +722,14 @@ namespace basegfx
|
||||
bool bOOXMLMotionPath)
|
||||
{
|
||||
const sal_uInt32 nCount(rPolyPolygon.count());
|
||||
OUStringBuffer aResult;
|
||||
sal_uInt32 nCombinedPointCount = 0;
|
||||
for(sal_uInt32 i(0); i < nCount; i++)
|
||||
{
|
||||
const B2DPolygon& aPolygon(rPolyPolygon.getB2DPolygon(i));
|
||||
nCombinedPointCount += aPolygon.count();
|
||||
}
|
||||
|
||||
OUStringBuffer aResult(std::max<int>(nCombinedPointCount * 32,512));
|
||||
B2DPoint aCurrentSVGPosition(0.0, 0.0); // SVG assumes (0,0) as the initial current point
|
||||
|
||||
for(sal_uInt32 i(0); i < nCount; i++)
|
||||
|
||||
@@ -526,7 +526,7 @@ bool SbiScanner::NextSym()
|
||||
else
|
||||
aSym = aLine.copy( n, nCol - n - 1 );
|
||||
// get out duplicate string delimiters
|
||||
OUStringBuffer aSymBuf;
|
||||
OUStringBuffer aSymBuf(aSym.getLength());
|
||||
for ( sal_Int32 i = 0, len = aSym.getLength(); i < len; ++i )
|
||||
{
|
||||
aSymBuf.append( aSym[i] );
|
||||
|
||||
@@ -1544,7 +1544,7 @@ void SbRtl_Join(StarBASIC *, SbxArray & rPar, bool)
|
||||
{
|
||||
aDelim = " ";
|
||||
}
|
||||
OUStringBuffer aRetStr;
|
||||
OUStringBuffer aRetStr(32);
|
||||
short nLower, nUpper;
|
||||
pArr->GetDim( 1, nLower, nUpper );
|
||||
short aIdx[1];
|
||||
|
||||
@@ -35,7 +35,6 @@ static OUString ImpCurrencyToString( sal_Int64 rVal )
|
||||
sal_Unicode const cDecimalSep = '.';
|
||||
|
||||
OUString aAbsStr = OUString::number( absVal );
|
||||
OUStringBuffer aBuf;
|
||||
|
||||
sal_Int32 initialLen = aAbsStr.getLength();
|
||||
|
||||
@@ -53,6 +52,7 @@ static OUString ImpCurrencyToString( sal_Int64 rVal )
|
||||
if ( isNeg )
|
||||
++nCapacity;
|
||||
|
||||
OUStringBuffer aBuf( nCapacity );
|
||||
aBuf.setLength( nCapacity );
|
||||
|
||||
|
||||
|
||||
@@ -519,7 +519,7 @@ void SbxBasicFormater::ScanFormatString( double dNumber,
|
||||
nMultipleThousandSeparators;
|
||||
bool bPercent,bCurrency,bScientific,bGenerateThousandSeparator;
|
||||
|
||||
OUStringBuffer sReturnStrg;
|
||||
OUStringBuffer sReturnStrg(32);
|
||||
|
||||
// analyse the format-string, i. e. determine the following values:
|
||||
/*
|
||||
|
||||
@@ -142,12 +142,12 @@ namespace connectivity
|
||||
{
|
||||
OUString lcl_getPermittedJavaMethods_nothrow( const Reference< XComponentContext >& _rxContext )
|
||||
{
|
||||
OUStringBuffer aConfigPath;
|
||||
aConfigPath.append( "/org.openoffice.Office.DataAccess/DriverSettings/" );
|
||||
aConfigPath.append ( ODriverDelegator::getImplementationName_Static() );
|
||||
aConfigPath.append( "/PermittedJavaMethods" );
|
||||
OUString aConfigPath =
|
||||
"/org.openoffice.Office.DataAccess/DriverSettings/" +
|
||||
ODriverDelegator::getImplementationName_Static() +
|
||||
"/PermittedJavaMethods";
|
||||
::utl::OConfigurationTreeRoot aConfig( ::utl::OConfigurationTreeRoot::createWithComponentContext(
|
||||
_rxContext, aConfigPath.makeStringAndClear() ) );
|
||||
_rxContext, aConfigPath ) );
|
||||
|
||||
OUStringBuffer aPermittedMethods;
|
||||
const Sequence< OUString > aNodeNames( aConfig.getNodeNames() );
|
||||
|
||||
@@ -52,14 +52,17 @@ std::vector<OUString> lcl_splitColumnPart(const OUString& sColumnPart)
|
||||
std::vector<OUString> sParts = string::split(sColumnPart, sal_Unicode(u','));
|
||||
std::vector<OUString> sReturn;
|
||||
|
||||
OUStringBuffer current;
|
||||
OUStringBuffer current(128);
|
||||
for (auto const& part : sParts)
|
||||
{
|
||||
current.append(part);
|
||||
if (current.lastIndexOf("(") > current.lastIndexOf(")"))
|
||||
current.append(","); // it was false split
|
||||
else
|
||||
sReturn.push_back(current.makeStringAndClear());
|
||||
{
|
||||
sReturn.push_back(current.toString());
|
||||
current.setLength(0);
|
||||
}
|
||||
}
|
||||
return sReturn;
|
||||
}
|
||||
|
||||
@@ -136,7 +136,8 @@ void FbCreateStmtParser::ensureProperTableLengths() const
|
||||
OUString FbCreateStmtParser::compose() const
|
||||
{
|
||||
ensureProperTableLengths();
|
||||
OUStringBuffer sSql("CREATE TABLE ");
|
||||
OUStringBuffer sSql(128);
|
||||
sSql.append("CREATE TABLE ");
|
||||
sSql.append(getTableName());
|
||||
|
||||
lcl_appendWithSpace(sSql, "("); // column declaration
|
||||
|
||||
@@ -34,7 +34,7 @@ static OString DXFReadLine(SvStream& rIStm)
|
||||
sal_uLong nOldFilePos = rIStm.Tell();
|
||||
char c = 0;
|
||||
|
||||
OStringBuffer aBuf;
|
||||
OStringBuffer aBuf(512);
|
||||
|
||||
while( !bEnd && !rIStm.GetError() ) // !!! do not check for EOF
|
||||
// !!! because we read blockwise
|
||||
|
||||
@@ -34,7 +34,7 @@ OUString lclConvertToCanonicalName(const OUString& rFileName)
|
||||
sal_Int32 nLength = rFileName.getLength();
|
||||
const sal_Unicode* pString = rFileName.getStr();
|
||||
|
||||
OUStringBuffer aBuffer(nLength);
|
||||
OUStringBuffer aBuffer(nLength*2);
|
||||
|
||||
for (sal_Int32 i = 0; i < nLength; i++)
|
||||
{
|
||||
|
||||
@@ -55,7 +55,7 @@ class ManifestImport final : public cppu::WeakImplHelper < css::xml::sax::XDocum
|
||||
std::vector< css::beans::NamedValue > aKeyInfoSequence;
|
||||
std::vector< css::uno::Sequence< css::beans::NamedValue > > aKeys;
|
||||
std::vector< css::beans::PropertyValue > aSequence;
|
||||
OUStringBuffer aCurrentCharacters;
|
||||
OUStringBuffer aCurrentCharacters{64};
|
||||
ManifestStack aStack;
|
||||
bool bIgnoreEncryptData;
|
||||
bool bPgpEncryption;
|
||||
|
||||
+2
-2
@@ -964,14 +964,14 @@ SC_DLLPUBLIC void ScColToAlpha( OUStringBuffer& rBuffer, SCCOL nCol);
|
||||
|
||||
inline void ScColToAlpha( OUString& rStr, SCCOL nCol)
|
||||
{
|
||||
OUStringBuffer aBuf(2);
|
||||
OUStringBuffer aBuf(4);
|
||||
ScColToAlpha( aBuf, nCol);
|
||||
rStr += aBuf;
|
||||
}
|
||||
|
||||
inline OUString ScColToAlpha( SCCOL nCol )
|
||||
{
|
||||
OUStringBuffer aBuf(2);
|
||||
OUStringBuffer aBuf(4);
|
||||
ScColToAlpha( aBuf, nCol);
|
||||
return aBuf.makeStringAndClear();
|
||||
}
|
||||
|
||||
@@ -184,7 +184,7 @@ uno::Reference<rdf::XURI> createBaseURI(
|
||||
if (true) {
|
||||
xBaseURI.set( xPkgURI, uno::UNO_SET_THROW );
|
||||
}
|
||||
OUStringBuffer buf;
|
||||
OUStringBuffer buf(64);
|
||||
if (!xBaseURI->getUriReference().endsWith("/"))
|
||||
{
|
||||
const sal_Int32 count( xBaseURI->getPathSegmentCount() );
|
||||
|
||||
@@ -66,7 +66,7 @@ int parseEscaped(OUString const & part, sal_Int32 * index) {
|
||||
OUString parsePart(
|
||||
OUString const & part, bool namePart, sal_Int32 * index)
|
||||
{
|
||||
OUStringBuffer buf;
|
||||
OUStringBuffer buf(64);
|
||||
while (*index < part.getLength()) {
|
||||
sal_Unicode c = part[*index];
|
||||
if (namePart ? c == '?' : c == '&' || c == '=') {
|
||||
|
||||
@@ -79,7 +79,7 @@ OUString readLockFile(const OUString& aSource)
|
||||
aFileStream.ReadBytes(pBuffer.get(), nSize);
|
||||
|
||||
css::uno::Sequence<sal_Int8> aData(pBuffer.get(), nSize);
|
||||
OStringBuffer aResult;
|
||||
OStringBuffer aResult(static_cast<int>(nSize));
|
||||
for (sal_Int8 nByte : aData)
|
||||
{
|
||||
aResult.append(static_cast<sal_Char>(nByte));
|
||||
|
||||
@@ -178,7 +178,7 @@ void DocumentLockFile::WriteEntryToStream( const LockFileEntry& aEntry, const un
|
||||
{
|
||||
::osl::MutexGuard aGuard( m_aMutex );
|
||||
|
||||
OUStringBuffer aBuffer;
|
||||
OUStringBuffer aBuffer(256);
|
||||
|
||||
for ( LockFileComponent lft : o3tl::enumrange<LockFileComponent>() )
|
||||
{
|
||||
|
||||
@@ -130,7 +130,7 @@ LockFileEntry LockFileCommon::ParseEntry( const uno::Sequence< sal_Int8 >& aBuff
|
||||
|
||||
OUString LockFileCommon::ParseName( const uno::Sequence< sal_Int8 >& aBuffer, sal_Int32& io_nCurPos )
|
||||
{
|
||||
OStringBuffer aResult;
|
||||
OStringBuffer aResult(128);
|
||||
bool bHaveName = false;
|
||||
bool bEscape = false;
|
||||
|
||||
@@ -168,7 +168,7 @@ OUString LockFileCommon::ParseName( const uno::Sequence< sal_Int8 >& aBuffer, sa
|
||||
|
||||
OUString LockFileCommon::EscapeCharacters( const OUString& aSource )
|
||||
{
|
||||
OUStringBuffer aBuffer;
|
||||
OUStringBuffer aBuffer(aSource.getLength()*2);
|
||||
const sal_Unicode* pStr = aSource.getStr();
|
||||
for ( sal_Int32 nInd = 0; nInd < aSource.getLength() && pStr[nInd] != 0; nInd++ )
|
||||
{
|
||||
|
||||
@@ -1647,7 +1647,7 @@ short SvNumberformat::ImpNextSymbol(OUStringBuffer& rString,
|
||||
sal_Unicode cLetter = ' '; // Preliminary result
|
||||
sal_Int32 nLen = rString.getLength();
|
||||
ScanState eState = SsStart;
|
||||
OUStringBuffer sBuffSymbol(32);
|
||||
OUStringBuffer sBuffSymbol(64);
|
||||
|
||||
const NfKeywordTable & rKeywords = rScan.GetKeywords();
|
||||
while (nPos < nLen && eState != SsStop)
|
||||
@@ -2426,7 +2426,7 @@ bool SvNumberformat::GetOutputString(double fNumber,
|
||||
Color** ppColor)
|
||||
{
|
||||
bool bRes = false;
|
||||
OUStringBuffer sBuff;
|
||||
OUStringBuffer sBuff(64);
|
||||
OutString.clear();
|
||||
*ppColor = nullptr; // No color change
|
||||
if (eType & SvNumFormatType::LOGICAL)
|
||||
@@ -5523,10 +5523,10 @@ void SvNumberformat::impTransliterateImpl(OUStringBuffer& rStr,
|
||||
{
|
||||
css::lang::Locale aLocale( LanguageTag( rNum.GetLang() ).getLocale() );
|
||||
|
||||
OUString sTemp(rStr.makeStringAndClear());
|
||||
OUString sTemp(rStr.toString());
|
||||
sTemp = GetFormatter().GetNatNum()->getNativeNumberStringParams(
|
||||
sTemp, aLocale, rNum.GetNatNum(), rNum.GetParams());
|
||||
rStr.append(sTemp);
|
||||
rStr = sTemp;
|
||||
}
|
||||
|
||||
OUString SvNumberformat::impTransliterateImpl(const OUString& rStr,
|
||||
|
||||
@@ -406,7 +406,8 @@ OString exceptionToString(const css::uno::Any & caught)
|
||||
void DbgUnhandledException(const css::uno::Any & caught, const char* currentFunction, const char* fileAndLineNo,
|
||||
const char* area, const char* explanatory)
|
||||
{
|
||||
OStringBuffer sMessage( "DBG_UNHANDLED_EXCEPTION in " );
|
||||
OStringBuffer sMessage( 512 );
|
||||
sMessage.append( "DBG_UNHANDLED_EXCEPTION in " );
|
||||
sMessage.append(currentFunction);
|
||||
if (explanatory)
|
||||
{
|
||||
|
||||
@@ -1449,7 +1449,8 @@ bool INetURLObject::setAbsURIRef(OUString const & rTheAbsURIRef,
|
||||
}
|
||||
|
||||
void INetURLObject::changeScheme(INetProtocol eTargetScheme) {
|
||||
OUString aTmpStr=m_aAbsURIRef.makeStringAndClear();
|
||||
OUString aTmpStr=m_aAbsURIRef.toString();
|
||||
m_aAbsURIRef.setLength(0);
|
||||
int oldSchemeLen = 0;
|
||||
if (m_eScheme == INetProtocol::Generic)
|
||||
oldSchemeLen = m_aScheme.getLength();
|
||||
@@ -3365,7 +3366,7 @@ OUString INetURLObject::encodeText(sal_Unicode const * pBegin,
|
||||
rtl_TextEncoding eCharset,
|
||||
bool bKeepVisibleEscapes)
|
||||
{
|
||||
OUStringBuffer aResult;
|
||||
OUStringBuffer aResult(256);
|
||||
while (pBegin < pEnd)
|
||||
{
|
||||
EscapeType eEscapeType;
|
||||
@@ -4022,7 +4023,7 @@ bool INetURLObject::setName(OUString const& rTheName, EncodeMechanism eMechanism
|
||||
while (p != pSegEnd && *p != ';')
|
||||
++p;
|
||||
|
||||
OUStringBuffer aNewPath;
|
||||
OUStringBuffer aNewPath(256);
|
||||
aNewPath.append(pPathBegin, pSegBegin - pPathBegin);
|
||||
aNewPath.append(encodeText(rTheName, PART_PCHAR, eMechanism, eCharset, true));
|
||||
aNewPath.append(p, pPathEnd - p);
|
||||
|
||||
@@ -894,12 +894,14 @@ namespace
|
||||
nTextLen = OUString(OUString::number(rFormatter.GetMin())).getLength();
|
||||
string::padToLength(aBuf, nTextLen, '9');
|
||||
Size aMinTextSize = rSpinField.CalcMinimumSizeForText(
|
||||
rFormatter.CreateFieldText(aBuf.makeStringAndClear().toInt64()));
|
||||
rFormatter.CreateFieldText(aBuf.toString().toInt64()));
|
||||
aBuf.setLength(0);
|
||||
|
||||
nTextLen = OUString(OUString::number(rFormatter.GetMax())).getLength();
|
||||
string::padToLength(aBuf, nTextLen, '9');
|
||||
Size aMaxTextSize = rSpinField.CalcMinimumSizeForText(
|
||||
rFormatter.CreateFieldText(aBuf.makeStringAndClear().toInt64()));
|
||||
rFormatter.CreateFieldText(aBuf.toString().toInt64()));
|
||||
aBuf.setLength(0);
|
||||
|
||||
Size aRet(std::max(aMinTextSize.Width(), aMaxTextSize.Width()),
|
||||
std::max(aMinTextSize.Height(), aMaxTextSize.Height()));
|
||||
|
||||
@@ -1320,7 +1320,7 @@ std::unique_ptr<SalLayout> OutputDevice::ImplGlyphFallbackLayout( std::unique_pt
|
||||
// get list of code units that need glyph fallback
|
||||
int nCharPos = -1;
|
||||
bool bRTL = false;
|
||||
OUStringBuffer aMissingCodeBuf;
|
||||
OUStringBuffer aMissingCodeBuf(512);
|
||||
while (rLayoutArgs.GetNextPos( &nCharPos, &bRTL))
|
||||
aMissingCodeBuf.append(rLayoutArgs.mrStr[nCharPos]);
|
||||
rLayoutArgs.ResetPos();
|
||||
|
||||
@@ -1181,7 +1181,7 @@ RTFError RTFDocumentImpl::resolveChars(char ch)
|
||||
return RTFError::OK;
|
||||
}
|
||||
|
||||
OStringBuffer aBuf;
|
||||
OStringBuffer aBuf(512);
|
||||
|
||||
bool bUnicodeChecked = false;
|
||||
bool bSkipped = false;
|
||||
@@ -1275,8 +1275,9 @@ RTFError RTFDocumentImpl::resolveChars(char ch)
|
||||
return RTFError::OK;
|
||||
}
|
||||
|
||||
OUString aOUStr(OStringToOUString(aStr, m_aStates.top().getCurrentEncoding()));
|
||||
SAL_INFO("writerfilter.rtf", "RTFDocumentImpl::resolveChars: collected '" << aOUStr << "'");
|
||||
SAL_INFO("writerfilter.rtf",
|
||||
"RTFDocumentImpl::resolveChars: collected '"
|
||||
<< OStringToOUString(aStr, m_aStates.top().getCurrentEncoding()) << "'");
|
||||
|
||||
if (m_aStates.top().getDestination() == Destination::COLORTABLE)
|
||||
{
|
||||
@@ -2323,7 +2324,7 @@ RTFError RTFDocumentImpl::popState()
|
||||
{
|
||||
OUString aOrig = pValue->getString();
|
||||
|
||||
OUStringBuffer aBuf;
|
||||
OUStringBuffer aBuf(aOrig.getLength() * 2);
|
||||
sal_Int32 nReplaces = 1;
|
||||
for (int i = 0; i < aOrig.getLength(); i++)
|
||||
{
|
||||
@@ -2337,7 +2338,7 @@ RTFError RTFDocumentImpl::popState()
|
||||
- aState.getLevelNumbers().size()));
|
||||
}
|
||||
else
|
||||
aBuf.append(std::u16string_view(aOrig).substr(i, 1));
|
||||
aBuf.append(aOrig[i]);
|
||||
}
|
||||
|
||||
pValue->setString(aBuf.makeStringAndClear());
|
||||
@@ -3566,7 +3567,8 @@ void RTFDocumentImpl::checkUnicode(bool bUnicode, bool bHex)
|
||||
{
|
||||
if (bUnicode && !m_aUnicodeBuffer.isEmpty())
|
||||
{
|
||||
OUString aString = m_aUnicodeBuffer.makeStringAndClear();
|
||||
OUString aString = m_aUnicodeBuffer.toString();
|
||||
m_aUnicodeBuffer.setLength(0);
|
||||
text(aString);
|
||||
}
|
||||
if (bHex && !m_aHexBuffer.isEmpty())
|
||||
@@ -3575,7 +3577,8 @@ void RTFDocumentImpl::checkUnicode(bool bUnicode, bool bHex)
|
||||
if (m_aStates.top().getDestination() == Destination::FONTENTRY
|
||||
&& m_aStates.top().getCurrentEncoding() == RTL_TEXTENCODING_SYMBOL)
|
||||
nEncoding = RTL_TEXTENCODING_MS_1252;
|
||||
OUString aString = OStringToOUString(m_aHexBuffer.makeStringAndClear(), nEncoding);
|
||||
OUString aString = OStringToOUString(m_aHexBuffer.toString(), nEncoding);
|
||||
m_aHexBuffer.setLength(0);
|
||||
text(aString);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -590,7 +590,7 @@ private:
|
||||
sal_uInt16 m_nMinute;
|
||||
|
||||
/// Text from special destinations.
|
||||
OUStringBuffer m_aDestinationText;
|
||||
OUStringBuffer m_aDestinationText{ 512 };
|
||||
/// point to the buffer of the current destination
|
||||
OUStringBuffer* m_pCurrentDestinationText;
|
||||
|
||||
@@ -931,9 +931,9 @@ private:
|
||||
/// For the INCLUDEPICTURE field's argument.
|
||||
OUString m_aPicturePath;
|
||||
// Unicode characters are collected here so we don't have to send them one by one.
|
||||
OUStringBuffer m_aUnicodeBuffer;
|
||||
OUStringBuffer m_aUnicodeBuffer{ 512 };
|
||||
/// Same for hex characters.
|
||||
OStringBuffer m_aHexBuffer;
|
||||
OStringBuffer m_aHexBuffer{ 512 };
|
||||
/// Formula import.
|
||||
oox::formulaimport::XmlStreamBuilder m_aMathBuffer;
|
||||
/// Normal text property, that is math italic and math spacing are not applied to the current run.
|
||||
|
||||
@@ -182,7 +182,7 @@ void RTFTokenizer::popGroup() { m_nGroup--; }
|
||||
RTFError RTFTokenizer::resolveKeyword()
|
||||
{
|
||||
char ch;
|
||||
OStringBuffer aBuf;
|
||||
OStringBuffer aBuf(32);
|
||||
bool bNeg = false;
|
||||
bool bParam = false;
|
||||
int nParam = 0;
|
||||
@@ -202,6 +202,10 @@ RTFError RTFTokenizer::resolveKeyword()
|
||||
while (rtl::isAsciiAlpha(static_cast<unsigned char>(ch)))
|
||||
{
|
||||
aBuf.append(ch);
|
||||
if (aBuf.getLength() > 32)
|
||||
// See RTF spec v1.9.1, page 7
|
||||
// A control word's name cannot be longer than 32 letters.
|
||||
throw io::BufferSizeExceededException();
|
||||
Strm().ReadChar(ch);
|
||||
if (Strm().eof())
|
||||
{
|
||||
@@ -209,10 +213,6 @@ RTFError RTFTokenizer::resolveKeyword()
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (aBuf.getLength() > 32)
|
||||
// See RTF spec v1.9.1, page 7
|
||||
// A control word's name cannot be longer than 32 letters.
|
||||
throw io::BufferSizeExceededException();
|
||||
|
||||
if (ch == '-')
|
||||
{
|
||||
|
||||
@@ -71,7 +71,7 @@ class ModuleElement
|
||||
|
||||
OUString const _aLocalName;
|
||||
css::uno::Reference< css::xml::input::XAttributes > _xAttributes;
|
||||
OUStringBuffer _strBuffer;
|
||||
OUStringBuffer _strBuffer{512};
|
||||
|
||||
public:
|
||||
ModuleElement(
|
||||
|
||||
Reference in New Issue
Block a user