Skip to content

Commit

Permalink
create appendCopy method in OUStringBuffer
Browse files Browse the repository at this point in the history
so we can avoid temporary copies when appending a substring of an
OUString to the buffer. I would have preferred to call the method just
"append" but that results in ambiguous method errors when the callsite
is something like
   sal_Int32 n;
   OUStringBuffer s;
   s.append(n, 10);
I'm not sure why

Change-Id: I6b5b6641fcb5b26ce2269f89ef06e03c0b6aa76f
Reviewed-on: https://gerrit.libreoffice.org/58666
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
  • Loading branch information
Noel Grandin committed Aug 14, 2018
1 parent 095e1ca commit cd66852
Show file tree
Hide file tree
Showing 55 changed files with 144 additions and 103 deletions.
2 changes: 1 addition & 1 deletion basic/source/comp/codegen.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ void SbiCodeGen::Save()
{
aIfaceProcName.append(aPropPrefix);
}
aIfaceProcName.append(aPureProcName.copy( rIfaceName.getLength() + 1 ));
aIfaceProcName.appendCopy(aPureProcName, rIfaceName.getLength() + 1 );
aIfaceName = rIfaceName;
nPassCount = 2;
break;
Expand Down
2 changes: 1 addition & 1 deletion basic/source/runtime/runtime.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2051,7 +2051,7 @@ void SbiRuntime::StepRSET()
}
else
{
aNewStr.append(aRefValString.copy(0, nVarStrLen));
aNewStr.appendCopy(aRefValString, 0, nVarStrLen);
}
refVar->PutString(aNewStr.makeStringAndClear());

Expand Down
2 changes: 1 addition & 1 deletion comphelper/source/misc/string.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ OUString removeAny(OUString const& rIn,
{
if (i > 0)
{
buf.append(rIn.copy(0, i));
buf.appendCopy(rIn, 0, i);
}
isFound = true;
}
Expand Down
2 changes: 1 addition & 1 deletion configmgr/qa/unit/test.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ void normalize(
} else {
OUStringBuffer buf(path);
buf.append('/');
buf.append(relative.copy(0, i));
buf.appendCopy(relative, 0, i);
*normalizedPath = buf.makeStringAndClear();
*name = relative.copy(i + 1);
}
Expand Down
4 changes: 2 additions & 2 deletions connectivity/source/commontools/dbtools2.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ OUString createStandardTypePart(const Reference< XPropertySet >& xColProp,const
}
else
{
aSql.append(sTypeName.copy(0,++nParenPos));
aSql.appendCopy(sTypeName, 0, ++nParenPos);
}

if ( nPrecision > 0 && nDataType != DataType::TIMESTAMP )
Expand All @@ -149,7 +149,7 @@ OUString createStandardTypePart(const Reference< XPropertySet >& xColProp,const
else
{
nParenPos = sTypeName.indexOf(')',nParenPos);
aSql.append(sTypeName.copy(nParenPos));
aSql.appendCopy(sTypeName, nParenPos);
}
}
else
Expand Down
4 changes: 2 additions & 2 deletions connectivity/source/drivers/firebird/Clob.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ OUString SAL_CALL Clob::getSubString(sal_Int64 nPosition,
if( nCharsToCopy > nLength )
nCharsToCopy = nLength;
// append relevant part of first segment
sSegmentBuffer.append( sSegment.copy(0, nCharsToCopy ) );
sSegmentBuffer.appendCopy( sSegment, 0, nCharsToCopy );
nActLen += sSegmentBuffer.getLength();
}
}
Expand All @@ -115,7 +115,7 @@ OUString SAL_CALL Clob::getSubString(sal_Int64 nPosition,
RTL_TEXTENCODING_UTF8 );
sal_Int32 nStrLen = sSegment.getLength();
if( nActLen + nStrLen > nLength )
sSegmentBuffer.append(sSegment.copy(0, nLength - nActLen) );
sSegmentBuffer.appendCopy(sSegment, 0, nLength - nActLen);
else
sSegmentBuffer.append(sSegment);
nActLen += nStrLen;
Expand Down
4 changes: 2 additions & 2 deletions connectivity/source/drivers/firebird/PreparedStatement.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,9 @@ sal_Int64 toNumericWithoutDecimalPlace(const OUString& sSource)
OUStringBuffer sBuffer(15);
if(nDotIndex > 0)
{
sBuffer.append(sNumber.copy(0, nDotIndex));
sBuffer.appendCopy(sNumber, 0, nDotIndex);
}
sBuffer.append(sNumber.copy(nDotIndex + 1));
sBuffer.appendCopy(sNumber, nDotIndex + 1);
return sBuffer.makeStringAndClear().toInt64();
}
}
Expand Down
2 changes: 1 addition & 1 deletion desktop/source/app/updater.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ std::string download_content(const OString& rURL, bool bFile, OUString& rHash)
{
OUString aTempFileURL = aTempFile.GetURL();
OString aTempFileURLOString = OUStringToOString(aTempFileURL, RTL_TEXTENCODING_UTF8);
response_body.append(aTempFileURLOString.getStr(), aTempFileURLOString.getLength());
response_body.append(aTempFileURLOString);

aTempFile.EnableKillingFile(false);

Expand Down
2 changes: 1 addition & 1 deletion desktop/source/deployment/misc/dp_misc.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ OUString makeURL( OUString const & baseURL, OUString const & relPath_ )
{
OUStringBuffer buf;
if (baseURL.getLength() > 1 && baseURL[ baseURL.getLength() - 1 ] == '/')
buf.append( baseURL.copy( 0, baseURL.getLength() - 1 ) );
buf.appendCopy( baseURL, 0, baseURL.getLength() - 1 );
else
buf.append( baseURL );
OUString relPath(relPath_);
Expand Down
12 changes: 6 additions & 6 deletions desktop/source/deployment/misc/dp_ucb.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -215,18 +215,18 @@ bool readLine( OUString * res, OUString const & startingWith,
{
pos = file.indexOf( LF, pos );
if (pos < 0) { // EOF
buf.append( file.copy( start ) );
buf.appendCopy( file, start );
}
else
{
if (pos > 0 && file[ pos - 1 ] == CR)
{
// consume extra CR
buf.append( file.copy( start, pos - start - 1 ) );
buf.appendCopy( file, start, pos - start - 1 );
++pos;
}
else
buf.append( file.copy( start, pos - start ) );
buf.appendCopy( file, start, pos - start );
++pos; // consume LF
// check next line:
if (pos < file.getLength() &&
Expand Down Expand Up @@ -270,16 +270,16 @@ bool readProperties( std::vector< std::pair< OUString, OUString> > & out_result,
bool bEOF = false;
pos = file.indexOf( LF, pos );
if (pos < 0) { // EOF
buf.append( file.copy( start ) );
buf.appendCopy( file, start );
bEOF = true;
}
else
{
if (pos > 0 && file[ pos - 1 ] == CR)
// consume extra CR
buf.append( file.copy( start, pos - start - 1 ) );
buf.appendCopy( file, start, pos - start - 1 );
else
buf.append( file.copy( start, pos - start ) );
buf.appendCopy( file, start, pos - start );
pos++;
}
OUString aLine = buf.makeStringAndClear();
Expand Down
2 changes: 1 addition & 1 deletion editeng/source/editeng/editdoc.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1647,7 +1647,7 @@ OUString ContentNode::GetExpandedText(sal_Int32 nStartPos, sal_Int32 nEndPos) co
DBG_ASSERT( nEnd >= nIndex, "End in front of the index?" );
//!! beware of sub string length of -1
if (nEnd > nIndex)
aStr.append( GetString().copy(nIndex, nEnd - nIndex) );
aStr.appendCopy( GetString(), nIndex, nEnd - nIndex );

if ( pNextFeature )
{
Expand Down
5 changes: 3 additions & 2 deletions editeng/source/misc/svxacorr.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2805,11 +2805,12 @@ const SvxAutocorrWord* SvxAutocorrWordList::WordMatches(const SvxAutocorrWord *p
nTmp++;
if (nTmp < nSttWdPos)
break; // word delimiter found
buf.append(rTxt.copy(nFndPos, nSttWdPos - nFndPos)).append(pFnd->GetLong());
buf.appendCopy(rTxt, nFndPos, nSttWdPos - nFndPos).append(pFnd->GetLong());
nFndPos = nSttWdPos + sTmp.getLength();
}
} while (nSttWdPos != -1);
if (nEndPos - nFndPos > extra_repl) buf.append(rTxt.copy(nFndPos, nEndPos - nFndPos));
if (nEndPos - nFndPos > extra_repl)
buf.appendCopy(rTxt, nFndPos, nEndPos - nFndPos);
aLong = buf.makeStringAndClear();
}
SvxAutocorrWord* pNew = new SvxAutocorrWord(aShort, aLong);
Expand Down
2 changes: 1 addition & 1 deletion forms/source/component/Filter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ namespace frm
// To fix this, we would probably have to revert here to always return "1" or "0" as normalized
// filter, and change our client code to properly translate this (which could be some effort).
if ( nMarkerPos == 0 )
aText.append( sText.copy( sExpressionMarker.getLength() ) );
aText.appendCopy( sText, sExpressionMarker.getLength() );
else
{
// fallback
Expand Down
4 changes: 2 additions & 2 deletions framework/source/uielement/toolbarsmenucontroller.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ void ToolbarsMenuController::fillPopupMenu( Reference< css::awt::XPopupMenu > co

sal_Int32 n = aSortedTbs[i].aCommand.lastIndexOf( '/' );
if (( n > 0 ) && (( n+1 ) < aSortedTbs[i].aCommand.getLength() ))
aStrBuf.append( aSortedTbs[i].aCommand.copy( n+1 ));
aStrBuf.appendCopy( aSortedTbs[i].aCommand, n+1 );

OUString aCmd( aStrBuf.makeStringAndClear() );

Expand Down Expand Up @@ -664,7 +664,7 @@ void SAL_CALL ToolbarsMenuController::itemSelected( const css::awt::MenuEvent& r
if (( nIndex > 0 ) && (( nIndex+1 ) < aCmd.getLength() ))
{
OUStringBuffer aBuf( "private:resource/toolbar/" );
aBuf.append( aCmd.copy( nIndex+1 ));
aBuf.appendCopy( aCmd, nIndex+1 );

bool bShow( !pVCLPopupMenu->IsItemChecked( rEvent.MenuId ));
OUString aToolBarResName( aBuf.makeStringAndClear() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -880,13 +880,13 @@ void cclass_Unicode::parseText( ParseResult& r, const OUString& rText, sal_Int32
{
if ( cLast == '\\' )
{ // escaped
aSymbol.append(rText.getStr() + postSymbolIndex, nextCharIndex - postSymbolIndex - 2);
aSymbol.appendCopy(rText, postSymbolIndex, nextCharIndex - postSymbolIndex - 2);
aSymbol.append(OUString(&current, 1));
}
else
{
eState = ssStop;
aSymbol.append(rText.getStr() + postSymbolIndex, nextCharIndex - postSymbolIndex - 1);
aSymbol.appendCopy(rText, postSymbolIndex, nextCharIndex - postSymbolIndex - 1);
}
postSymbolIndex = nextCharIndex;
}
Expand All @@ -905,21 +905,21 @@ void cclass_Unicode::parseText( ParseResult& r, const OUString& rText, sal_Int32
{
if ( cLast == '\\' )
{ // escaped
aSymbol.append(rText.getStr() + postSymbolIndex, nextCharIndex - postSymbolIndex - 2);
aSymbol.appendCopy(rText, postSymbolIndex, nextCharIndex - postSymbolIndex - 2);
aSymbol.append(OUString(&current, 1));
}
else if (current == nextChar &&
!(nContTypes & KParseTokens::TWO_DOUBLE_QUOTES_BREAK_STRING) )
{ // "" => literal " escaped
aSymbol.append(rText.getStr() + postSymbolIndex, nextCharIndex - postSymbolIndex);
aSymbol.appendCopy(rText, postSymbolIndex, nextCharIndex - postSymbolIndex);
nextCharIndex = index;
if (index < rText.getLength()) { ++nCodePoints; }
nextChar = (index < rText.getLength()) ? rText.iterateCodePoints(&index) : 0;
}
else
{
eState = ssStop;
aSymbol.append(rText.getStr() + postSymbolIndex, nextCharIndex - postSymbolIndex - 1);
aSymbol.appendCopy(rText, postSymbolIndex, nextCharIndex - postSymbolIndex - 1);
}
postSymbolIndex = nextCharIndex;
}
Expand Down Expand Up @@ -1028,7 +1028,7 @@ void cclass_Unicode::parseText( ParseResult& r, const OUString& rText, sal_Int32
{
if (postSymbolIndex < nextCharIndex)
{ //! open quote
aSymbol.append(rText.getStr() + postSymbolIndex, nextCharIndex - postSymbolIndex - 1);
aSymbol.appendCopy(rText, postSymbolIndex, nextCharIndex - postSymbolIndex - 1);
r.TokenType |= KParseType::MISSING_QUOTE;
}
r.DequotedNameOrString = aSymbol.toString();
Expand Down
4 changes: 2 additions & 2 deletions i18npool/source/nativenumber/nativenumbersupplier.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,7 @@ OUString getHebrewNativeNumberString(const OUString& aNumberString, bool useGere
makeHebrewNumber(value, output, true, useGeresh);

if (i < len)
output.append(aNumberString.copy(i));
output.appendCopy(aNumberString,i);

return output.makeStringAndClear();
}
Expand Down Expand Up @@ -1191,7 +1191,7 @@ OUString getCyrillicNativeNumberString(const OUString& aNumberString)
makeCyrillicNumber(value, output, true);

if (i < len)
output.append(aNumberString.copy(i));
output.appendCopy(aNumberString,i);

return output.makeStringAndClear();
}
Expand Down
41 changes: 41 additions & 0 deletions include/rtl/ustrbuf.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,47 @@ public:
return append( str.getStr(), str.getLength() );
}

#ifdef LIBO_INTERNAL_ONLY
/**
Appends a substring of an OUString, starting at position beginIndex.
The characters of the <code>OUString</code> argument are appended, in
order, to the contents of this string buffer.
@param str a string.
@param beginIndex the beginning index, inclusive. Must be >= 0 and <= the length of str.
@return this string buffer.
@since LibreOffice 6.2
*/
OUStringBuffer & appendCopy(const OUString &str, sal_Int32 beginIndex)
{
assert(beginIndex >=0 && beginIndex <= str.getLength());
return append( str.getStr() + beginIndex, str.getLength() - beginIndex );
}

/**
Appends a substring of an OUString, starting at position beginIndex,
running for count characters.
The characters of the <code>OUString</code> argument are appended, in
order, to the contents of this string buffer.
@param str a string.
@param beginIndex the beginning index, inclusive. Must be >= 0 and <= the length of str.
@param count must be >= 0 and <= (str.length() - beginIndex).
@return this string buffer.
@since LibreOffice 6.2
*/
OUStringBuffer & appendCopy(const OUString &str, sal_Int32 beginIndex, sal_Int32 count)
{
assert(beginIndex >=0 && beginIndex <= str.getLength());
assert(count >=0 && count <= (str.getLength() - beginIndex));
return append( str.getStr() + beginIndex, count );
}
#endif // LIBO_INTERNAL_ONLY

/**
Appends the content of a stringbuffer to this string buffer.
Expand Down
2 changes: 1 addition & 1 deletion oox/source/core/relationshandler.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ OUString lclGetRelationsPath( const OUString& rFragmentPath )
return
OUStringBuffer( rFragmentPath.copy( 0, nPathLen ) ). // file path including slash
append( "_rels/" ). // additional '_rels/' path
append( rFragmentPath.copy( nPathLen ) ). // file name after path
appendCopy( rFragmentPath, nPathLen ). // file name after path
append( ".rels" ). // '.rels' suffix
makeStringAndClear();
}
Expand Down
6 changes: 3 additions & 3 deletions oox/source/dump/dumperbase.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ void StringHelper::appendEncString( OUStringBuffer& rStr, const OUString& rData,
if( (nBeg == 0) && (nIdx == nEnd) )
rStr.append( rData );
else
rStr.append( rData.copy( nBeg, nIdx - nBeg ) );
rStr.appendCopy( rData, nBeg, nIdx - nBeg );
}
// append characters to be encoded
while( (nIdx < nEnd) && (rData[ nIdx ] < 0x20) )
Expand Down Expand Up @@ -562,7 +562,7 @@ OUString lclTrimQuotedStringList( const OUString& rStr )
{
// seek to next quote character and add text portion to token buffer
sal_Int32 nEnd = lclIndexOf( rStr, OOX_DUMP_CFG_QUOTE, nPos );
aToken.append( rStr.copy( nPos, nEnd - nPos ) );
aToken.appendCopy( rStr, nPos, nEnd - nPos );
// process literal quotes
while( (nEnd + 1 < nLen) && (rStr[ nEnd ] == OOX_DUMP_CFG_QUOTE) && (rStr[ nEnd + 1 ] == OOX_DUMP_CFG_QUOTE) )
{
Expand All @@ -585,7 +585,7 @@ OUString lclTrimQuotedStringList( const OUString& rStr )
{
// find list separator, add token text to buffer
sal_Int32 nEnd = lclIndexOf( rStr, OOX_DUMP_CFG_LISTSEP, nPos );
aBuffer.append( rStr.copy( nPos, nEnd - nPos ) );
aBuffer.appendCopy( rStr, nPos, nEnd - nPos );
if( nEnd < nLen )
aBuffer.append( OOX_DUMP_LF );
// set current position behind list separator
Expand Down
4 changes: 2 additions & 2 deletions opencl/source/openclconfig.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ OUString getToken(const OUString& string, sal_Int32& index)
while ((p = token.indexOf('%', i)) >= 0)
{
if (p > i)
result.append(token.copy(i, p - i));
result.appendCopy(token, i, p - i);
if (p < token.getLength() - 2)
{
result.append(OUStringLiteral1(token.copy(p+1, 2).toInt32(16)));
Expand All @@ -87,7 +87,7 @@ OUString getToken(const OUString& string, sal_Int32& index)
i = token.getLength();
}
}
result.append(token.copy(i));
result.appendCopy(token,i);

return result.makeStringAndClear();
}
Expand Down
2 changes: 1 addition & 1 deletion registry/source/keyimpl.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,7 @@ OUString ORegKey::getFullPath(OUString const & path) const {
OUStringBuffer b(m_name);
if (!b.isEmpty() && b[b.getLength() - 1] == '/') {
if (path[0] == '/') {
b.append(path.copy(1));
b.appendCopy(path,1);
} else {
b.append(path);
}
Expand Down
2 changes: 1 addition & 1 deletion sax/source/tools/converter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ void Converter::convertDuration(OUStringBuffer& rBuffer,
if ( aNS.getLength() > 2 )
{
rBuffer.append( '.');
rBuffer.append( aNS.copy( 2 ) ); // strip "0."
rBuffer.appendCopy( aNS, 2 ); // strip "0."
}
}
rBuffer.append( 'S');
Expand Down
2 changes: 1 addition & 1 deletion sc/source/core/tool/address.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2154,7 +2154,7 @@ static void lcl_ScRange_Format_XL_Header( OUStringBuffer& rString, const ScRange
{
if (!aDocName.isEmpty())
{
rString.append("'[").append(aDocName).append("]").append(aTabName.copy(1));
rString.append("'[").append(aDocName).append("]").appendCopy(aTabName, 1);
}
else
{
Expand Down
Loading

0 comments on commit cd66852

Please sign in to comment.