summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2022-05-12 14:33:06 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2022-05-13 11:11:27 +0200
commit3817965ded6c7ed915e4f9599e18b3e8abdaca44 (patch)
treee112927919e8b7c9ce6c1e233ff6fce05f189784
parent8ad920befe1290c40ef762e8d7d9797b1924f5d2 (diff)
add SvStream::ReadLine(OStringBuffer... to reduce OString allocation
and use it where possible Change-Id: I3efc7a642f73661ce606c917c0323ba9948521c6 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134265 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r--connectivity/source/drivers/hsqldb/HDriver.cxx4
-rw-r--r--cui/source/options/personalization.cxx2
-rw-r--r--idl/source/prj/command.cxx4
-rw-r--r--include/tools/stream.hxx2
-rw-r--r--linguistic/source/dicimp.cxx6
-rw-r--r--oox/source/export/drawingml.cxx7
-rw-r--r--oox/source/export/vmlexport.cxx6
-rw-r--r--sc/source/ui/docshell/impex.cxx2
-rw-r--r--sd/source/filter/html/htmlex.cxx4
-rw-r--r--sd/source/ui/view/sdview3.cxx6
-rw-r--r--sfx2/source/bastyp/mieclip.cxx13
-rw-r--r--svx/source/tbxctrls/Palette.cxx12
-rw-r--r--sw/source/core/edit/edtox.cxx2
-rw-r--r--sw/source/ui/dbui/mmresultdialogs.cxx2
-rw-r--r--sw/source/uibase/dbui/dbmgr.cxx2
-rw-r--r--tools/source/stream/stream.cxx13
-rw-r--r--vcl/source/edit/texteng.cxx2
-rw-r--r--vcl/source/image/ImplImageTree.cxx3
-rw-r--r--vcl/source/treelist/imap2.cxx4
-rw-r--r--vcl/source/treelist/transfer.cxx2
20 files changed, 55 insertions, 43 deletions
diff --git a/connectivity/source/drivers/hsqldb/HDriver.cxx b/connectivity/source/drivers/hsqldb/HDriver.cxx
index 39475e715e5d..aa874c6120f2 100644
--- a/connectivity/source/drivers/hsqldb/HDriver.cxx
+++ b/connectivity/source/drivers/hsqldb/HDriver.cxx
@@ -252,7 +252,7 @@ namespace connectivity
std::unique_ptr<SvStream> pStream( ::utl::UcbStreamHelper::CreateStream(xStream) );
if (pStream)
{
- OString sLine;
+ OStringBuffer sLine;
OString sVersionString;
while ( pStream->ReadLine(sLine) )
{
@@ -260,7 +260,7 @@ namespace connectivity
continue;
sal_Int32 nIdx {0};
const std::string_view sIniKey = o3tl::getToken(sLine, 0, '=', nIdx);
- const OString sValue = sLine.getToken(0, '=', nIdx);
+ const OString sValue(o3tl::getToken(sLine, 0, '=', nIdx));
if( sIniKey == "hsqldb.compatible_version" )
{
sVersionString = sValue;
diff --git a/cui/source/options/personalization.cxx b/cui/source/options/personalization.cxx
index 7c6f01a7fe77..ec62fb105353 100644
--- a/cui/source/options/personalization.cxx
+++ b/cui/source/options/personalization.cxx
@@ -114,9 +114,9 @@ void SvxPersonalizationTabPage::LoadDefaultImages()
sal_Int32 nIndex = 0;
bool foundOne = false;
+ OStringBuffer aLine;
while (aStream.IsOpen() && !aStream.eof() && nIndex < MAX_DEFAULT_PERSONAS)
{
- OString aLine;
OUString aPersonaSetting, aPreviewFile, aName;
sal_Int32 nParseIndex = 0;
diff --git a/idl/source/prj/command.cxx b/idl/source/prj/command.cxx
index 15d08d99d39c..0c9436ce313e 100644
--- a/idl/source/prj/command.cxx
+++ b/idl/source/prj/command.cxx
@@ -136,7 +136,7 @@ static bool ResponseFile( std::vector<OUString> * pList, int argc, char ** argv
if( aStm.GetError() != ERRCODE_NONE )
return false;
- OString aStr;
+ OStringBuffer aStr;
while( aStm.ReadLine( aStr ) )
{
sal_uInt16 n = 0;
@@ -153,7 +153,7 @@ static bool ResponseFile( std::vector<OUString> * pList, int argc, char ** argv
static_cast<unsigned char>(aStr[n]) ) )
n++;
if( n != nPos )
- pList->push_back( OStringToOUString(aStr.subView(nPos, n - nPos), RTL_TEXTENCODING_ASCII_US) );
+ pList->push_back( OStringToOUString(std::string_view(aStr).substr(nPos, n - nPos), RTL_TEXTENCODING_ASCII_US) );
}
}
}
diff --git a/include/tools/stream.hxx b/include/tools/stream.hxx
index 9c9591a86355..897af71d5021 100644
--- a/include/tools/stream.hxx
+++ b/include/tools/stream.hxx
@@ -25,6 +25,7 @@
#include <tools/ref.hxx>
#include <vcl/errcode.hxx>
#include <rtl/string.hxx>
+#include <rtl/strbuf.hxx>
#include <o3tl/typed_flags_set.hxx>
#include <memory>
#include <string_view>
@@ -293,6 +294,7 @@ public:
@endcode
causing endless loops ...
*/
+ bool ReadLine( OStringBuffer& rStr, sal_Int32 nMaxBytesToRead = 0xFFFE );
bool ReadLine( OString& rStr, sal_Int32 nMaxBytesToRead = 0xFFFE );
bool WriteLine( std::string_view rStr );
diff --git a/linguistic/source/dicimp.cxx b/linguistic/source/dicimp.cxx
index 59e88fd009e5..803445b4ef28 100644
--- a/linguistic/source/dicimp.cxx
+++ b/linguistic/source/dicimp.cxx
@@ -124,7 +124,7 @@ sal_Int16 ReadDicVersion( SvStream& rStream, LanguageType &nLng, bool &bNeg, OUS
!strcmp(pMagicHeader, pVerOOo7))
{
bool bSuccess;
- OString aLine;
+ OStringBuffer aLine;
nDicVersion = DIC_VERSION_7;
@@ -165,7 +165,7 @@ sal_Int16 ReadDicVersion( SvStream& rStream, LanguageType &nLng, bool &bNeg, OUS
EXTENSION_FOR_TITLE_TEXT;
}
- if (aLine.indexOf("---") != -1) // end of header
+ if (std::string_view(aLine).find("---") != std::string_view::npos) // end of header
break;
}
if (!bSuccess)
@@ -362,7 +362,7 @@ ErrCode DictionaryNeo::loadEntries(const OUString &rMainURL)
}
else if (DIC_VERSION_7 == nDicVersion)
{
- OString aLine;
+ OStringBuffer aLine;
// remaining lines - stock strings (a [==] b)
while (pStream->ReadLine(aLine))
diff --git a/oox/source/export/drawingml.cxx b/oox/source/export/drawingml.cxx
index eb588076e213..18e6e2723e89 100644
--- a/oox/source/export/drawingml.cxx
+++ b/oox/source/export/drawingml.cxx
@@ -108,6 +108,7 @@
#include <comphelper/xmltools.hxx>
#include <o3tl/any.hxx>
#include <o3tl/safeint.hxx>
+#include <o3tl/string_view.hxx>
#include <tools/stream.hxx>
#include <unotools/fontdefs.hxx>
#include <vcl/cvtgrf.hxx>
@@ -3707,14 +3708,14 @@ static std::map< OString, std::vector<OString> > lcl_getAdjNames()
SvFileStream aStream(aPath, StreamMode::READ);
if (aStream.GetError() != ERRCODE_NONE)
SAL_WARN("oox.shape", "failed to open oox-drawingml-adj-names");
- OString aLine;
+ OStringBuffer aLine;
bool bNotDone = aStream.ReadLine(aLine);
while (bNotDone)
{
sal_Int32 nIndex = 0;
// Each line is in a "key\tvalue" format: read the key, the rest is the value.
- OString aKey = aLine.getToken(0, '\t', nIndex);
- OString aValue = aLine.copy(nIndex);
+ OString aKey( o3tl::getToken(aLine, 0, '\t', nIndex) );
+ OString aValue( std::string_view(aLine).substr(nIndex) );
aRet[aKey].push_back(aValue);
bNotDone = aStream.ReadLine(aLine);
}
diff --git a/oox/source/export/vmlexport.cxx b/oox/source/export/vmlexport.cxx
index 32f60ff65c9a..8ee5c28ed67a 100644
--- a/oox/source/export/vmlexport.cxx
+++ b/oox/source/export/vmlexport.cxx
@@ -1138,13 +1138,13 @@ static std::vector<OString> lcl_getShapeTypes()
SvFileStream aStream(aPath, StreamMode::READ);
if (aStream.GetError() != ERRCODE_NONE)
SAL_WARN("oox", "failed to open vml-shape-types");
- OString aLine;
+ OStringBuffer aLine;
bool bNotDone = aStream.ReadLine(aLine);
while (bNotDone)
{
// Filter out comments.
- if (!aLine.startsWith("/"))
- aRet.push_back(aLine);
+ if (!o3tl::starts_with(aLine, "/"))
+ aRet.push_back(OString(aLine));
bNotDone = aStream.ReadLine(aLine);
}
return aRet;
diff --git a/sc/source/ui/docshell/impex.cxx b/sc/source/ui/docshell/impex.cxx
index 24869ab5b6f3..76ddae4f2ef1 100644
--- a/sc/source/ui/docshell/impex.cxx
+++ b/sc/source/ui/docshell/impex.cxx
@@ -2053,7 +2053,7 @@ bool ScImportExport::Sylk2Doc( SvStream& rStrm )
{
OUString aLine;
OUString aText;
- OString aByteLine;
+ OStringBuffer aByteLine;
SCCOL nCol = nStartCol;
SCROW nRow = nStartRow;
SCCOL nRefCol = nCol;
diff --git a/sd/source/filter/html/htmlex.cxx b/sd/source/filter/html/htmlex.cxx
index e76925f82917..072ac3c27165 100644
--- a/sd/source/filter/html/htmlex.cxx
+++ b/sd/source/filter/html/htmlex.cxx
@@ -2839,11 +2839,11 @@ bool HtmlExport::CopyScript( std::u16string_view rPath, const OUString& rSource,
if( pIStm )
{
- OString aLine;
+ OStringBuffer aLine;
while( pIStm->ReadLine( aLine ) )
{
- aScriptBuf.appendAscii( aLine.getStr() );
+ aScriptBuf.appendAscii( aLine.getStr(), aLine.getLength() );
if( bUnix )
{
aScriptBuf.append("\n");
diff --git a/sd/source/ui/view/sdview3.cxx b/sd/source/ui/view/sdview3.cxx
index 68941d2dd988..b72e837c4ea6 100644
--- a/sd/source/ui/view/sdview3.cxx
+++ b/sd/source/ui/view/sdview3.cxx
@@ -346,11 +346,11 @@ bool View::InsertData( const TransferableDataHelper& rDataHelper,
{
xStm->Seek( 0 );
- OString aLine;
+ OStringBuffer aLine;
while (xStm->ReadLine(aLine))
{
- sal_Int32 x = aLine.indexOf( "\\trowd" );
- if (x != -1)
+ size_t x = std::string_view(aLine).find( "\\trowd" );
+ if (x != std::string_view::npos)
{
bTable = true;
nFormat = bIsRTF ? SotClipboardFormatId::RTF : SotClipboardFormatId::RICHTEXT;
diff --git a/sfx2/source/bastyp/mieclip.cxx b/sfx2/source/bastyp/mieclip.cxx
index 580c6444d326..e40c5bd2970a 100644
--- a/sfx2/source/bastyp/mieclip.cxx
+++ b/sfx2/source/bastyp/mieclip.cxx
@@ -35,7 +35,7 @@ SvStream* MSE40HTMLClipFormatObj::IsValid( SvStream& rStream )
bool bRet = false;
pStrm.reset();
- OString sLine;
+ OStringBuffer sLine;
sal_Int32 nStt = -1, nEnd = -1, nFragStart = -1, nFragEnd = -1;
sal_Int32 nIndex = 0;
@@ -49,16 +49,17 @@ SvStream* MSE40HTMLClipFormatObj::IsValid( SvStream& rStream )
{
nIndex = 0;
std::string_view sTmp(o3tl::getToken(sLine, 0, ':', nIndex));
+ std::string_view sView(sLine);
if (sTmp == "StartHTML")
- nStt = o3tl::toInt32(sLine.subView(nIndex));
+ nStt = o3tl::toInt32(sView.substr(nIndex));
else if (sTmp == "EndHTML")
- nEnd = o3tl::toInt32(sLine.subView(nIndex));
+ nEnd = o3tl::toInt32(sView.substr(nIndex));
else if (sTmp == "StartFragment")
- nFragStart = o3tl::toInt32(sLine.subView(nIndex));
+ nFragStart = o3tl::toInt32(sView.substr(nIndex));
else if (sTmp == "EndFragment")
- nFragEnd = o3tl::toInt32(sLine.subView(nIndex));
+ nFragEnd = o3tl::toInt32(sView.substr(nIndex));
else if (sTmp == "SourceURL")
- sBaseURL = OStringToOUString( sLine.subView(nIndex), RTL_TEXTENCODING_UTF8 );
+ sBaseURL = OStringToOUString( sView.substr(nIndex), RTL_TEXTENCODING_UTF8 );
if (nEnd >= 0 && nStt >= 0 &&
(!sBaseURL.isEmpty() || rStream.Tell() >= o3tl::make_unsigned(nStt)))
diff --git a/svx/source/tbxctrls/Palette.cxx b/svx/source/tbxctrls/Palette.cxx
index fabccc8f2022..84858c2eb208 100644
--- a/svx/source/tbxctrls/Palette.cxx
+++ b/svx/source/tbxctrls/Palette.cxx
@@ -172,7 +172,7 @@ void PaletteASE::LoadPalette()
// PaletteGPL ------------------------------------------------------------------
-static OString lcl_getToken(const OString& rStr, sal_Int32& index);
+static OString lcl_getToken(OStringBuffer& rStr, sal_Int32& index);
PaletteGPL::PaletteGPL( const OUString &rFPath, const OUString &rFName ) :
mbLoadedPalette( false ),
@@ -254,7 +254,7 @@ void PaletteGPL::LoadPalette()
if( !mbValidPalette ) return;
- OString aLine;
+ OStringBuffer aLine;
do {
if (aLine[0] != '#' && aLine[0] != '\n')
{
@@ -274,9 +274,9 @@ void PaletteGPL::LoadPalette()
if(token.isEmpty()) continue;
sal_Int32 b = token.toInt32();
- OString name;
+ std::string_view name;
if(nIndex != -1)
- name = aLine.copy(nIndex);
+ name = std::string_view(aLine).substr(nIndex);
maColors.emplace_back(
Color(r, g, b),
@@ -287,7 +287,7 @@ void PaletteGPL::LoadPalette()
// finds first token in rStr from index, separated by whitespace
// returns position of next token in index
-static OString lcl_getToken(const OString& rStr, sal_Int32& index)
+static OString lcl_getToken(OStringBuffer& rStr, sal_Int32& index)
{
sal_Int32 substart, toklen = 0;
OUString aWhitespaceChars( " \n\t" );
@@ -317,7 +317,7 @@ static OString lcl_getToken(const OString& rStr, sal_Int32& index)
if(index == rStr.getLength())
index = -1;
- return rStr.copy(substart, toklen);
+ return OString(std::string_view(rStr).substr(substart, toklen));
}
// PaletteSOC ------------------------------------------------------------------
diff --git a/sw/source/core/edit/edtox.cxx b/sw/source/core/edit/edtox.cxx
index df58e49cdbaa..1a9c4ba213f7 100644
--- a/sw/source/core/edit/edtox.cxx
+++ b/sw/source/core/edit/edtox.cxx
@@ -316,9 +316,9 @@ void SwEditShell::ApplyAutoMark()
SearchAlgorithms2::ABSOLUTE,
'\\' );
+ OStringBuffer aRdLine;
while (rStrm.good())
{
- OString aRdLine;
rStrm.ReadLine( aRdLine );
// # -> comment
diff --git a/sw/source/ui/dbui/mmresultdialogs.cxx b/sw/source/ui/dbui/mmresultdialogs.cxx
index 1727a1bbb758..b2db4782bd6c 100644
--- a/sw/source/ui/dbui/mmresultdialogs.cxx
+++ b/sw/source/ui/dbui/mmresultdialogs.cxx
@@ -1187,7 +1187,7 @@ IMPL_LINK_NOARG(SwMMResultEmailDialog, SendDocumentsHdl_Impl, weld::Button&, voi
OSL_FAIL("no output file created?");
continue;
}
- OString sLine;
+ OStringBuffer sLine;
bool bDone = pInStream->ReadLine( sLine );
while ( bDone )
{
diff --git a/sw/source/uibase/dbui/dbmgr.cxx b/sw/source/uibase/dbui/dbmgr.cxx
index f7607bac9dda..0d526bab42c3 100644
--- a/sw/source/uibase/dbui/dbmgr.cxx
+++ b/sw/source/uibase/dbui/dbmgr.cxx
@@ -985,7 +985,7 @@ static rtl::Reference<SwMailMessage> lcl_CreateMailFromDoc(
return pMessage;
pInStream->SetStreamCharSet( sMailEncoding );
- OString sLine;
+ OStringBuffer sLine;
while ( pInStream->ReadLine( sLine ) )
{
sBody.append(OStringToOUString( sLine, sMailEncoding ));
diff --git a/tools/source/stream/stream.cxx b/tools/source/stream/stream.cxx
index c69b2d053231..9ab7291e3bfc 100644
--- a/tools/source/stream/stream.cxx
+++ b/tools/source/stream/stream.cxx
@@ -426,13 +426,21 @@ bool SvStream::ReadByteStringLine( OUString& rStr, rtl_TextEncoding eSrcCharSet,
bool SvStream::ReadLine( OString& rStr, sal_Int32 nMaxBytesToRead )
{
+ OStringBuffer aBuf(4096);
+ bool rv = ReadLine(aBuf, nMaxBytesToRead);
+ rStr = aBuf.makeStringAndClear();
+ return rv;
+}
+
+bool SvStream::ReadLine( OStringBuffer& aBuf, sal_Int32 nMaxBytesToRead )
+{
char buf[256+1];
bool bEnd = false;
sal_uInt64 nOldFilePos = Tell();
char c = 0;
std::size_t nTotalLen = 0;
- OStringBuffer aBuf(4096);
+ aBuf.setLength(0);
while( !bEnd && !GetError() ) // Don't test for EOF as we
// are reading block-wise!
{
@@ -443,7 +451,7 @@ bool SvStream::ReadLine( OString& rStr, sal_Int32 nMaxBytesToRead )
{
// Exit on first block-read error
m_isEof = true;
- rStr.clear();
+ aBuf.setLength(0);
return false;
}
else
@@ -494,7 +502,6 @@ bool SvStream::ReadLine( OString& rStr, sal_Int32 nMaxBytesToRead )
if ( bEnd )
m_isEof = false;
- rStr = aBuf.makeStringAndClear();
return bEnd;
}
diff --git a/vcl/source/edit/texteng.cxx b/vcl/source/edit/texteng.cxx
index 07ea9f783e5e..2b940ed9b6b9 100644
--- a/vcl/source/edit/texteng.cxx
+++ b/vcl/source/edit/texteng.cxx
@@ -2409,7 +2409,7 @@ bool TextEngine::Read( SvStream& rInput, const TextSelection* pSel )
if ( aSel.HasRange() )
aSel = ImpDeleteText( aSel );
- OString aLine;
+ OStringBuffer aLine;
bool bDone = rInput.ReadLine( aLine );
OUString aTmpStr(OStringToOUString(aLine, rInput.GetStreamCharSet()));
while ( bDone )
diff --git a/vcl/source/image/ImplImageTree.cxx b/vcl/source/image/ImplImageTree.cxx
index 827df39a32bc..5f2d1e94af6a 100644
--- a/vcl/source/image/ImplImageTree.cxx
+++ b/vcl/source/image/ImplImageTree.cxx
@@ -39,6 +39,7 @@
#include <osl/process.h>
#include <rtl/bootstrap.hxx>
#include <rtl/uri.hxx>
+#include <rtl/strbuf.hxx>
#include <tools/diagnose_ex.h>
#include <tools/stream.hxx>
@@ -588,7 +589,7 @@ void ImplImageTree::loadImageLinks()
void ImplImageTree::parseLinkFile(std::shared_ptr<SvStream> const & xStream)
{
- OString aLine;
+ OStringBuffer aLine;
OUString aLink, aOriginal;
int nLineNo = 0;
while (xStream->ReadLine(aLine))
diff --git a/vcl/source/treelist/imap2.cxx b/vcl/source/treelist/imap2.cxx
index fd308afe0608..4433c2b6d587 100644
--- a/vcl/source/treelist/imap2.cxx
+++ b/vcl/source/treelist/imap2.cxx
@@ -236,7 +236,7 @@ void ImageMap::ImpReadCERN( SvStream& rIStm )
// delete old content
ClearImageMap();
- OString aStr;
+ OStringBuffer aStr;
while ( rIStm.ReadLine( aStr ) )
ImpReadCERNLine( aStr );
}
@@ -369,7 +369,7 @@ void ImageMap::ImpReadNCSA( SvStream& rIStm )
// delete old content
ClearImageMap();
- OString aStr;
+ OStringBuffer aStr;
while ( rIStm.ReadLine( aStr ) )
ImpReadNCSALine( aStr );
}
diff --git a/vcl/source/treelist/transfer.cxx b/vcl/source/treelist/transfer.cxx
index 91132addfa94..4506fa2ffea7 100644
--- a/vcl/source/treelist/transfer.cxx
+++ b/vcl/source/treelist/transfer.cxx
@@ -1999,7 +1999,7 @@ bool TransferableDataHelper::GetFileList( FileList& rFileList ) const
{
if( aFlavor.MimeType.indexOf( "text/uri-list" ) > -1 )
{
- OString aDiskString;
+ OStringBuffer aDiskString;
while( xStm->ReadLine( aDiskString ) )
if( !aDiskString.isEmpty() && aDiskString[0] != '#' )