Kaydet (Commit) 28580110 authored tarafından Noel Grandin's avatar Noel Grandin

add operator+=(OUStringBuffer) method to OUString

to reduce needless object creation and copying some more

And fix what looks like a bug in CSS hex color parsing at line
609 in sw/../parcss1.cxx that has been there since
commit 7b0b5cdf "initial import"

Change-Id: Ibad42b23721a56493bd1edcd7165e6104494a5c3
Reviewed-on: https://gerrit.libreoffice.org/58357
Tested-by: Jenkins
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 58e266ae
......@@ -2188,7 +2188,7 @@ void WatchTreeListBox::RequestingChildren( SvTreeListEntry * pParent )
aDisplayName = pItem->maDisplayName;
else
aDisplayName = pItem->maName;
aDisplayName += aIndexStr.makeStringAndClear();
aDisplayName += aIndexStr;
pChildItem->maDisplayName = aDisplayName;
SvTreeListEntry* pChildEntry = SvTreeListBox::InsertEntry( aDisplayName, pEntry );
......
......@@ -3409,7 +3409,7 @@ void SbRtl_FormatNumber(StarBASIC*, SbxArray& rPar, bool)
{
OUStringBuffer sBuf;
comphelper::string::padToLength(sBuf, nNumDigitsAfterDecimal - nActualDigits, '0');
aResult += sBuf.makeStringAndClear();
aResult += sBuf;
}
}
......
......@@ -1897,7 +1897,7 @@ svx::SpellPortions SentenceEditWindow_Impl::CreateSpellPortions() const
}
else
{ // we just need to append the left-over text to the last portion (which had no errors)
aRet[ aRet.size() - 1 ].sText += aLeftOverText.makeStringAndClear();
aRet[ aRet.size() - 1 ].sText += aLeftOverText;
}
}
}
......
......@@ -1730,7 +1730,7 @@ void OSingleSelectQueryComposer::setConditionByColumn( const Reference< XPropert
sTemp += andCriteria ? OUString(STR_AND) : OUString(STR_OR);
sFilter = sTemp;
}
sFilter += aSQL.makeStringAndClear();
sFilter += aSQL;
// add the filter and the sort order
_aSetFunctor(this,sFilter);
......
......@@ -2214,7 +2214,7 @@ const FormulaToken* FormulaCompiler::CreateStringFromToken( OUString& rFormula,
{
OUStringBuffer aBuffer;
const FormulaToken* p = CreateStringFromToken( aBuffer, pTokenP );
rFormula += aBuffer.makeStringAndClear();
rFormula += aBuffer;
return p;
}
......
......@@ -459,7 +459,7 @@ void lcl_formatPersianWord( sal_Int32 nNumber, OUString& rsResult )
nNumber /= 1000;
nSection++;
}
rsResult += aTemp.makeStringAndClear();
rsResult += aTemp;
}
......@@ -536,7 +536,7 @@ void lcl_formatCharsGR(const sal_Unicode table[], int n, OUString& s )
}
sb.append(gr_smallNum(table,n));
s += sb.makeStringAndClear();
s += sb;
}
static
......
......@@ -59,6 +59,7 @@ namespace rtl
*/
class SAL_WARN_UNUSED OUStringBuffer
{
friend class OUString;
public:
/**
Constructs a string buffer with no characters in it and an
......@@ -1615,6 +1616,18 @@ private:
sal_Int32 nCapacity;
};
#if defined LIBO_INTERNAL_ONLY
// Define this here to avoid circular includes
inline OUString & OUString::operator+=( const OUStringBuffer & str ) &
{
// Call operator= if this is empty, otherwise rtl_uString_newConcat will attempt to
// acquire() the str.pData buffer, which is part of the OUStringBuffer mutable state.
if (isEmpty())
return operator=(str.toString());
else
return internalAppend(str.pData);
}
#endif
}
#ifdef RTL_STRING_UNITTEST
......
......@@ -56,6 +56,8 @@ extern bool rtl_string_unittest_invalid_conversion;
namespace rtl
{
class OUStringBuffer;
#ifdef RTL_STRING_UNITTEST
#undef rtl
#endif
......@@ -516,6 +518,18 @@ public:
}
#endif
#if defined LIBO_INTERNAL_ONLY
/**
Append the contents of an OUStringBuffer to this string.
@param str an OUStringBuffer.
@exception std::bad_alloc is thrown if an out-of-memory condition occurs
@since LibreOffice 6.2
*/
inline OUString & operator+=( const OUStringBuffer & str ) &;
#endif
/**
Append a string to this string.
......@@ -528,14 +542,7 @@ public:
&
#endif
{
rtl_uString* pNewData = NULL;
rtl_uString_newConcat( &pNewData, pData, str.pData );
if (pNewData == NULL) {
throw std::bad_alloc();
}
rtl_uString_assign(&pData, pNewData);
rtl_uString_release(pNewData);
return *this;
return internalAppend(str.pData);
}
#if defined LIBO_INTERNAL_ONLY
void operator+=(OUString const &) && = delete;
......@@ -3539,6 +3546,20 @@ public:
rtl_uString_newFromAscii( &pNew, value );
return OUString( pNew, SAL_NO_ACQUIRE );
}
private:
OUString & internalAppend( rtl_uString* pOtherData )
{
rtl_uString* pNewData = NULL;
rtl_uString_newConcat( &pNewData, pData, pOtherData );
if (pNewData == NULL) {
throw std::bad_alloc();
}
rtl_uString_assign(&pData, pNewData);
rtl_uString_release(pNewData);
return *this;
}
};
#if defined LIBO_INTERNAL_ONLY
......
......@@ -170,7 +170,7 @@ namespace io_acceptor {
buf.append( ",localHost=" );
buf.append( m_socket.getLocalHost() );
m_sDescription += buf.makeStringAndClear();
m_sDescription += buf;
}
sal_Int32 SocketConnection::read( Sequence < sal_Int8 > & aReadBytes , sal_Int32 nBytesToRead )
......
......@@ -113,7 +113,7 @@ namespace stoc_connector {
buf.append( ",localHost=" );
buf.append( m_socket.getLocalHost( ) );
m_sDescription += buf.makeStringAndClear();
m_sDescription += buf;
}
sal_Int32 SocketConnection::read( Sequence < sal_Int8 > & aReadBytes , sal_Int32 nBytesToRead )
......
......@@ -945,7 +945,7 @@ inline void ScColToAlpha( OUString& rStr, SCCOL nCol)
{
OUStringBuffer aBuf(2);
ScColToAlpha( aBuf, nCol);
rStr += aBuf.makeStringAndClear();
rStr += aBuf;
}
inline OUString ScColToAlpha( SCCOL nCol )
......
......@@ -537,7 +537,8 @@ HtmlTokenId HTMLParser::ScanText( const sal_Unicode cBreak )
else
{
// If not scanning a tag return token
aToken += sTmpBuffer.makeStringAndClear();
aToken += sTmpBuffer;
sTmpBuffer.setLength(0);
if( !aToken.isEmpty() )
{
......@@ -588,7 +589,10 @@ HtmlTokenId HTMLParser::ScanText( const sal_Unicode cBreak )
// options.
sTmpBuffer.append( '\\' );
if( MAX_LEN == sTmpBuffer.getLength() )
aToken += sTmpBuffer.makeStringAndClear();
{
aToken += sTmpBuffer;
sTmpBuffer.setLength(0);
}
}
if( IsParserWorking() )
{
......@@ -626,7 +630,10 @@ HtmlTokenId HTMLParser::ScanText( const sal_Unicode cBreak )
// mark within tags
sTmpBuffer.append( '\\' );
if( MAX_LEN == sTmpBuffer.getLength() )
aToken += sTmpBuffer.makeStringAndClear();
{
aToken += sTmpBuffer;
sTmpBuffer.setLength(0);
}
}
sTmpBuffer.append( '\\' );
break;
......@@ -721,7 +728,8 @@ HtmlTokenId HTMLParser::ScanText( const sal_Unicode cBreak )
if( !aToken.isEmpty() || sTmpBuffer.getLength() > 1 )
{
// Have seen s.th. aside from blanks?
aToken += sTmpBuffer.makeStringAndClear();
aToken += sTmpBuffer;
sTmpBuffer.setLength(0);
return HtmlTokenId::TEXTTOKEN;
}
else
......@@ -747,14 +755,15 @@ HtmlTokenId HTMLParser::ScanText( const sal_Unicode cBreak )
sTmpBuffer.appendUtf32( nNextCh );
if( MAX_LEN == sTmpBuffer.getLength() )
{
aToken += sTmpBuffer.makeStringAndClear();
aToken += sTmpBuffer;
sTmpBuffer.setLength(0);
}
if( ( sal_Unicode(EOF) == (nNextCh = GetNextChar()) &&
rInput.eof() ) ||
!IsParserWorking() )
{
if( !sTmpBuffer.isEmpty() )
aToken += sTmpBuffer.makeStringAndClear();
aToken += sTmpBuffer;
return HtmlTokenId::TEXTTOKEN;
}
} while( rtl::isAsciiAlpha( nNextCh ) || rtl::isAsciiDigit( nNextCh ) );
......@@ -763,14 +772,17 @@ HtmlTokenId HTMLParser::ScanText( const sal_Unicode cBreak )
}
if( MAX_LEN == sTmpBuffer.getLength() )
aToken += sTmpBuffer.makeStringAndClear();
{
aToken += sTmpBuffer;
sTmpBuffer.setLength(0);
}
if( bContinue && bNextCh )
nNextCh = GetNextChar();
}
if( !sTmpBuffer.isEmpty() )
aToken += sTmpBuffer.makeStringAndClear();
aToken += sTmpBuffer;
return HtmlTokenId::TEXTTOKEN;
}
......@@ -805,7 +817,8 @@ HtmlTokenId HTMLParser::GetNextRawToken()
// Maybe we've reached the end.
// Save what we have read previously...
aToken += sTmpBuffer.makeStringAndClear();
aToken += sTmpBuffer;
sTmpBuffer.setLength(0);
// and remember position in stream.
sal_uInt64 nStreamPos = rInput.Tell();
......@@ -926,7 +939,10 @@ HtmlTokenId HTMLParser::GetNextRawToken()
bTwoMinus = true;
if( MAX_LEN == sTmpBuffer.getLength() )
aToken += sTmpBuffer.makeStringAndClear();
{
aToken += sTmpBuffer;
sTmpBuffer.setLength(0);
}
sTmpBuffer.appendUtf32( nNextCh );
nNextCh = GetNextChar();
}
......@@ -978,7 +994,10 @@ HtmlTokenId HTMLParser::GetNextRawToken()
if( (!bContinue && !sTmpBuffer.isEmpty()) ||
MAX_LEN == sTmpBuffer.getLength() )
aToken += sTmpBuffer.makeStringAndClear();
{
aToken += sTmpBuffer;
sTmpBuffer.setLength(0);
}
if( bContinue && bNextCh )
nNextCh = GetNextChar();
......@@ -1055,13 +1074,19 @@ HtmlTokenId HTMLParser::GetNextToken_()
do {
sTmpBuffer.appendUtf32( nNextCh );
if( MAX_LEN == sTmpBuffer.getLength() )
aToken += sTmpBuffer.makeStringAndClear();
{
aToken += sTmpBuffer;
sTmpBuffer.setLength(0);
}
nNextCh = GetNextChar();
} while( '>' != nNextCh && '/' != nNextCh && !rtl::isAsciiWhiteSpace( nNextCh ) &&
IsParserWorking() && !rInput.eof() );
if( !sTmpBuffer.isEmpty() )
aToken += sTmpBuffer.makeStringAndClear();
{
aToken += sTmpBuffer;
sTmpBuffer.setLength(0);
}
// Skip blanks
while( rtl::isAsciiWhiteSpace( nNextCh ) && IsParserWorking() )
......
......@@ -106,14 +106,14 @@ int SvRTFParser::GetNextToken_()
aStrBuffer[nStrLen++] = nNextCh;
if( MAX_TOKEN_LEN == nStrLen )
{
aToken += aStrBuffer.toString();
aToken += aStrBuffer;
nStrLen = 0;
}
nNextCh = GetNextChar();
} while( RTF_ISALPHA( nNextCh ) );
if( nStrLen )
{
aToken += aStrBuffer.makeStringAndClear();
aToken += aStrBuffer;
}
}
......@@ -505,7 +505,7 @@ void SvRTFParser::ScanText()
if (sal_Unicode(EOF) == (nNextCh = GetNextChar()))
{
if (!aStrBuffer.isEmpty())
aToken += aStrBuffer.toString();
aToken += aStrBuffer;
return;
}
} while
......@@ -522,7 +522,7 @@ void SvRTFParser::ScanText()
}
if (!aStrBuffer.isEmpty())
aToken += aStrBuffer.makeStringAndClear();
aToken += aStrBuffer;
}
......
......@@ -151,7 +151,7 @@ CSS1Token CSS1Parser::GetNextToken()
} while( (rtl::isAsciiAlphanumeric(cNextCh) ||
'-' == cNextCh) && !IsEOF() );
aToken += sTmpBuffer.makeStringAndClear();
aToken += sTmpBuffer;
// check if we know it
switch( aToken[0] )
......@@ -244,7 +244,7 @@ CSS1Token CSS1Parser::GetNextToken()
} while( (rtl::isAsciiAlphanumeric(cNextCh) ||
'-' == cNextCh) && !IsEOF() );
aToken += sTmpBuffer.makeStringAndClear();
aToken += sTmpBuffer;
if( ( 'i'==aToken[0] || 'I'==aToken[0] ) &&
aToken.equalsIgnoreAsciiCase( "important" ) )
......@@ -282,7 +282,7 @@ CSS1Token CSS1Parser::GetNextToken()
cNextCh = GetNextChar();
} while( cQuoteChar != cNextCh && !IsEOF() );
aToken += sTmpBuffer.toString();
aToken += sTmpBuffer;
nRet = CSS1_STRING;
}
......@@ -320,7 +320,7 @@ CSS1Token CSS1Parser::GetNextToken()
if( sTmpBuffer.getLength()==6 )
{
// we found a color in hex
aToken += sTmpBuffer.makeStringAndClear();
aToken += sTmpBuffer;
nRet = CSS1_HEXCOLOR;
bNextCh = false;
......@@ -342,7 +342,7 @@ CSS1Token CSS1Parser::GetNextToken()
} while( (('0'<=cNextCh && '9'>=cNextCh) || '.'==cNextCh) &&
!IsEOF() );
aToken += sTmpBuffer.makeStringAndClear();
aToken += sTmpBuffer;
nValue = aToken.toDouble();
// ignore white space
......@@ -388,7 +388,7 @@ CSS1Token CSS1Parser::GetNextToken()
} while( (rtl::isAsciiAlphanumeric(cNextCh) ||
'-' == cNextCh) && !IsEOF() );
aIdent += sTmpBuffer2.makeStringAndClear();
aIdent += sTmpBuffer2;
// Is it an unit?
const sal_Char *pCmp1 = nullptr, *pCmp2 = nullptr, *pCmp3 = nullptr;
......@@ -544,7 +544,7 @@ CSS1Token CSS1Parser::GetNextToken()
if( sTmpBuffer.getLength()==6 || sTmpBuffer.getLength()==3 )
{
// we found a color in hex
aToken += sTmpBuffer.makeStringAndClear();
aToken += sTmpBuffer;
nRet = CSS1_HEXCOLOR;
bNextCh = false;
......@@ -601,7 +601,7 @@ CSS1Token CSS1Parser::GetNextToken()
} while( (rtl::isAsciiAlphanumeric(cNextCh) ||
'-' == cNextCh) && !IsEOF() );
aToken += sTmpBuffer.makeStringAndClear();
aToken += sTmpBuffer;
if( bHexColor && sTmpBuffer.getLength()==6 )
{
......@@ -628,7 +628,7 @@ CSS1Token CSS1Parser::GetNextToken()
cNextCh = GetNextChar();
} while( (nNestCnt>1 || ')'!=cNextCh) && !IsEOF() );
sTmpBuffer2.append( cNextCh );
aToken += sTmpBuffer2.makeStringAndClear();
aToken += sTmpBuffer2;
bNextCh = true;
nRet = 'u'==aToken[0] || 'U'==aToken[0]
? CSS1_URL
......
......@@ -192,8 +192,8 @@ bool ImplCurrencyGetValue( const OUString& rStr, BigInt& rValue,
if (aStr2.getLength() < nDecDigits)
string::padToLength(aStr2, nDecDigits, '0');
aStr1.append(aStr2);
aStr = aStr1.makeStringAndClear();
aStr += aStr2.makeStringAndClear();
// check range
BigInt nValue( aStr );
......
......@@ -145,7 +145,7 @@ void Imp_PutDoubleChar(OUString& rStr, double fValue)
{
OUStringBuffer sStringBuffer;
::sax::Converter::convertDouble(sStringBuffer, fValue);
rStr += sStringBuffer.makeStringAndClear();
rStr += sStringBuffer;
}
void Imp_PutDoubleChar(OUStringBuffer& rStr, const SvXMLUnitConverter& rConv, double fValue,
......
......@@ -267,7 +267,7 @@ namespace xmloff
if ( !_rStrExpValue.isEmpty() )
_rStrExpValue += " ";
_rStrExpValue += aOut.makeStringAndClear();
_rStrExpValue += aOut;
return true;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment