summaryrefslogtreecommitdiff
path: root/tools/source/stream
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 /tools/source/stream
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>
Diffstat (limited to 'tools/source/stream')
-rw-r--r--tools/source/stream/stream.cxx13
1 files changed, 10 insertions, 3 deletions
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;
}