diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-07-31 13:13:36 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-08-01 21:39:28 +0200 |
commit | 28580110807a38e3ba6f8385f22871b8dfe0a910 (patch) | |
tree | 33ff5f3c25316926f14ffbb837025090465c2a2a | |
parent | 58e266ae808dbf3e157b38eb2c8f24774131e0f8 (diff) |
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 7b0b5cdfeed656b279bc32cd929630d5fc25878b "initial import"
Change-Id: Ibad42b23721a56493bd1edcd7165e6104494a5c3
Reviewed-on: https://gerrit.libreoffice.org/58357
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r-- | basctl/source/basicide/baside2b.cxx | 2 | ||||
-rw-r--r-- | basic/source/runtime/methods.cxx | 2 | ||||
-rw-r--r-- | cui/source/dialogs/SpellDialog.cxx | 2 | ||||
-rw-r--r-- | dbaccess/source/core/api/SingleSelectQueryComposer.cxx | 2 | ||||
-rw-r--r-- | formula/source/core/api/FormulaCompiler.cxx | 2 | ||||
-rw-r--r-- | i18npool/source/defaultnumberingprovider/defaultnumberingprovider.cxx | 4 | ||||
-rw-r--r-- | include/rtl/ustrbuf.hxx | 13 | ||||
-rw-r--r-- | include/rtl/ustring.hxx | 37 | ||||
-rw-r--r-- | io/source/acceptor/acc_socket.cxx | 2 | ||||
-rw-r--r-- | io/source/connector/ctr_socket.cxx | 2 | ||||
-rw-r--r-- | sc/inc/address.hxx | 2 | ||||
-rw-r--r-- | svtools/source/svhtml/parhtml.cxx | 51 | ||||
-rw-r--r-- | svtools/source/svrtf/parrtf.cxx | 8 | ||||
-rw-r--r-- | sw/source/filter/html/parcss1.cxx | 18 | ||||
-rw-r--r-- | vcl/source/control/longcurr.cxx | 2 | ||||
-rw-r--r-- | xmloff/source/draw/xexptran.cxx | 2 | ||||
-rw-r--r-- | xmloff/source/forms/controlpropertyhdl.cxx | 2 |
17 files changed, 106 insertions, 47 deletions
diff --git a/basctl/source/basicide/baside2b.cxx b/basctl/source/basicide/baside2b.cxx index 26c8b5170bf0..bcd09142536c 100644 --- a/basctl/source/basicide/baside2b.cxx +++ b/basctl/source/basicide/baside2b.cxx @@ -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 ); diff --git a/basic/source/runtime/methods.cxx b/basic/source/runtime/methods.cxx index 756c9d044f87..4a1a6b66cd29 100644 --- a/basic/source/runtime/methods.cxx +++ b/basic/source/runtime/methods.cxx @@ -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; } } diff --git a/cui/source/dialogs/SpellDialog.cxx b/cui/source/dialogs/SpellDialog.cxx index 7552ce613fcb..d71f12a41ac6 100644 --- a/cui/source/dialogs/SpellDialog.cxx +++ b/cui/source/dialogs/SpellDialog.cxx @@ -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; } } } diff --git a/dbaccess/source/core/api/SingleSelectQueryComposer.cxx b/dbaccess/source/core/api/SingleSelectQueryComposer.cxx index 06a4dcfc4285..9a8eea35ed10 100644 --- a/dbaccess/source/core/api/SingleSelectQueryComposer.cxx +++ b/dbaccess/source/core/api/SingleSelectQueryComposer.cxx @@ -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); diff --git a/formula/source/core/api/FormulaCompiler.cxx b/formula/source/core/api/FormulaCompiler.cxx index 3329db657812..019a4b292267 100644 --- a/formula/source/core/api/FormulaCompiler.cxx +++ b/formula/source/core/api/FormulaCompiler.cxx @@ -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; } diff --git a/i18npool/source/defaultnumberingprovider/defaultnumberingprovider.cxx b/i18npool/source/defaultnumberingprovider/defaultnumberingprovider.cxx index 813e2451b7bf..7d4dc4542f9a 100644 --- a/i18npool/source/defaultnumberingprovider/defaultnumberingprovider.cxx +++ b/i18npool/source/defaultnumberingprovider/defaultnumberingprovider.cxx @@ -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 diff --git a/include/rtl/ustrbuf.hxx b/include/rtl/ustrbuf.hxx index 1a40eeee8832..5f696bff906d 100644 --- a/include/rtl/ustrbuf.hxx +++ b/include/rtl/ustrbuf.hxx @@ -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 diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx index 1731bb905c76..24005b22333d 100644 --- a/include/rtl/ustring.hxx +++ b/include/rtl/ustring.hxx @@ -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 diff --git a/io/source/acceptor/acc_socket.cxx b/io/source/acceptor/acc_socket.cxx index c8e85cd33185..b106e8b11526 100644 --- a/io/source/acceptor/acc_socket.cxx +++ b/io/source/acceptor/acc_socket.cxx @@ -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 ) diff --git a/io/source/connector/ctr_socket.cxx b/io/source/connector/ctr_socket.cxx index e5908d6e41ed..255c2f0af534 100644 --- a/io/source/connector/ctr_socket.cxx +++ b/io/source/connector/ctr_socket.cxx @@ -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 ) diff --git a/sc/inc/address.hxx b/sc/inc/address.hxx index 63ddb00188ba..9d123383c961 100644 --- a/sc/inc/address.hxx +++ b/sc/inc/address.hxx @@ -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 ) diff --git a/svtools/source/svhtml/parhtml.cxx b/svtools/source/svhtml/parhtml.cxx index d887f4084ab8..a25f6f547517 100644 --- a/svtools/source/svhtml/parhtml.cxx +++ b/svtools/source/svhtml/parhtml.cxx @@ -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() ) diff --git a/svtools/source/svrtf/parrtf.cxx b/svtools/source/svrtf/parrtf.cxx index 91a53b4381c6..bff4bcacc54e 100644 --- a/svtools/source/svrtf/parrtf.cxx +++ b/svtools/source/svrtf/parrtf.cxx @@ -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; } diff --git a/sw/source/filter/html/parcss1.cxx b/sw/source/filter/html/parcss1.cxx index 181ebbd04b43..51bad26ca3ec 100644 --- a/sw/source/filter/html/parcss1.cxx +++ b/sw/source/filter/html/parcss1.cxx @@ -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 diff --git a/vcl/source/control/longcurr.cxx b/vcl/source/control/longcurr.cxx index cc5da9b3409c..f2a741abb6d6 100644 --- a/vcl/source/control/longcurr.cxx +++ b/vcl/source/control/longcurr.cxx @@ -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 ); diff --git a/xmloff/source/draw/xexptran.cxx b/xmloff/source/draw/xexptran.cxx index a771f0da7599..03e849d79873 100644 --- a/xmloff/source/draw/xexptran.cxx +++ b/xmloff/source/draw/xexptran.cxx @@ -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, diff --git a/xmloff/source/forms/controlpropertyhdl.cxx b/xmloff/source/forms/controlpropertyhdl.cxx index 839789167e9e..443ad538a2a2 100644 --- a/xmloff/source/forms/controlpropertyhdl.cxx +++ b/xmloff/source/forms/controlpropertyhdl.cxx @@ -267,7 +267,7 @@ namespace xmloff if ( !_rStrExpValue.isEmpty() ) _rStrExpValue += " "; - _rStrExpValue += aOut.makeStringAndClear(); + _rStrExpValue += aOut; return true; } |