desktop/source/app/dispatchwatcher.cxx | 5 ++--- idl/inc/lex.hxx | 3 ++- idl/source/cmptools/lex.cxx | 5 ++--- sc/source/ui/docshell/datastream.cxx | 4 +++- sdext/source/pdfimport/filterdet.cxx | 4 ++-- svtools/source/control/ctrlbox.cxx | 2 +- svx/source/tbxctrls/Palette.cxx | 11 ++++++----- tools/source/stream/stream.cxx | 2 +- vcl/skia/SkiaHelper.cxx | 2 +- 9 files changed, 20 insertions(+), 18 deletions(-)
New commits: commit b42fad8a35e1f16c5a6691dcbc32abc9830d8efa Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Sat May 31 15:38:32 2025 +0200 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Sat May 31 16:53:45 2025 +0200 Use ReadLine taking OStringBuffer to reduce allocations Change-Id: Ib180a1c67346eb6ce8cfbb6549b6e31e1b7911a7 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/186073 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> diff --git a/desktop/source/app/dispatchwatcher.cxx b/desktop/source/app/dispatchwatcher.cxx index faf830ffae3c..43f09bb9d5ae 100644 --- a/desktop/source/app/dispatchwatcher.cxx +++ b/desktop/source/app/dispatchwatcher.cxx @@ -725,10 +725,9 @@ bool DispatchWatcher::executeDispatchRequests( const std::vector<DispatchRequest if (fileForCat && fileForCat->IsValid()) { SvStream* aStream = fileForCat->GetStream(StreamMode::STD_READ); - while (aStream->good()) + OStringBuffer aStr; + while (aStream->ReadLine(aStr, SAL_MAX_INT32)) { - OString aStr; - aStream->ReadLine(aStr, SAL_MAX_INT32); for (sal_Int32 i = 0; i < aStr.getLength(); ++i) { std::cout << aStr[i]; diff --git a/idl/inc/lex.hxx b/idl/inc/lex.hxx index a45964f52353..1ae48b412a76 100644 --- a/idl/inc/lex.hxx +++ b/idl/inc/lex.hxx @@ -21,6 +21,7 @@ #include <sal/types.h> #include "hash.hxx" +#include <rtl/strbuf.hxx> #include <tools/stream.hxx> #include <vector> #include <memory> @@ -110,7 +111,7 @@ class SvTokenStream std::vector<std::unique_ptr<SvToken> > aTokList; std::vector<std::unique_ptr<SvToken> >::iterator pCurToken; - OString aBufStr; + OStringBuffer aBufStr; void InitCtor(); diff --git a/idl/source/cmptools/lex.cxx b/idl/source/cmptools/lex.cxx index e8fd0280d393..4ca8362e82d1 100644 --- a/idl/source/cmptools/lex.cxx +++ b/idl/source/cmptools/lex.cxx @@ -126,7 +126,6 @@ void SvTokenStream::FillTokenList() char SvTokenStream::GetNextChar() { - char nChar; while (aBufStr.getLength() <= nBufPos) { if (pInStream->ReadLine(aBufStr)) @@ -137,13 +136,13 @@ char SvTokenStream::GetNextChar() } else { - aBufStr.clear(); + aBufStr.setLength(0); nColumn = 0; nBufPos = 0; return ' } } - nChar = aBufStr[nBufPos++]; + char nChar = aBufStr[nBufPos++]; nColumn += nChar == ' ' ? nTabSize : 1; return nChar; } diff --git a/sc/source/ui/docshell/datastream.cxx b/sc/source/ui/docshell/datastream.cxx index 521dd930e484..975cc25ae258 100644 --- a/sc/source/ui/docshell/datastream.cxx +++ b/sc/source/ui/docshell/datastream.cxx @@ -192,10 +192,12 @@ private: } // Read & store new lines from stream. + OStringBuffer aBuffer; for (DataStream::Line & rLine : *oLines) { rLine.maCells.clear(); - mpStream->ReadLine(rLine.maLine); + mpStream->ReadLine(aBuffer); + rLine.maLine = aBuffer.toString(); // produces minimal string, and keeps buffer CSVHandler aHdl(rLine, mnColCount); orcus::csv_parser<CSVHandler> parser(rLine.maLine, aHdl, maConfig); parser.parse(); diff --git a/sdext/source/pdfimport/filterdet.cxx b/sdext/source/pdfimport/filterdet.cxx index 9d97b69b613d..65a4c6a15a83 100644 --- a/sdext/source/pdfimport/filterdet.cxx +++ b/sdext/source/pdfimport/filterdet.cxx @@ -693,9 +693,9 @@ static bool detectHasAdditionalStreams(const OUString& rSysUPath) std::vector<OString> aTrailingLines; const sal_uInt64 nLen = aHybridDetect.remainingSize(); aHybridDetect.Seek(nLen - std::min<sal_uInt64>(nLen, 4096)); - OString aLine; + OStringBuffer aLine; while (aHybridDetect.ReadLine(aLine)) - aTrailingLines.push_back(aLine); + aTrailingLines.push_back(aLine.toString()); // produces minimal string, and keeps buffer bool bAdditionalStreams(false); for (auto it = aTrailingLines.rbegin(); it != aTrailingLines.rend(); ++it) { diff --git a/svtools/source/control/ctrlbox.cxx b/svtools/source/control/ctrlbox.cxx index f73050d6a7b6..2cadcd57b518 100644 --- a/svtools/source/control/ctrlbox.cxx +++ b/svtools/source/control/ctrlbox.cxx @@ -464,7 +464,7 @@ void FontNameBox::LoadMRUEntries( const OUString& aFontMRUEntriesFile ) return; } - OString aLine; + OStringBuffer aLine; aStream.ReadLine( aLine ); OUString aEntries = OStringToOUString(aLine, RTL_TEXTENCODING_UTF8); diff --git a/svx/source/tbxctrls/Palette.cxx b/svx/source/tbxctrls/Palette.cxx index c509cab342e7..2f9afd67ce58 100644 --- a/svx/source/tbxctrls/Palette.cxx +++ b/svx/source/tbxctrls/Palette.cxx @@ -17,6 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <o3tl/string_view.hxx> #include <svx/Palette.hxx> #include <tools/stream.hxx> @@ -313,17 +314,17 @@ bool PaletteGPL::IsValid() bool PaletteGPL::ReadPaletteHeader(SvFileStream& rFileStream) { - OString aLine; - std::string_view aPaletteName; + OStringBuffer aLine; rFileStream.ReadLine(aLine); - if( !aLine.startsWith("GIMP Palette") ) return false; + if (!std::string_view(aLine).starts_with("GIMP Palette")) + return false; rFileStream.ReadLine(aLine); - if( aLine.startsWith("Name: ", &aPaletteName) ) + if (std::string_view aPaletteName; o3tl::starts_with(aLine, "Name: ", &aPaletteName)) { maGPLPaletteName = OStringToOUString(aPaletteName, RTL_TEXTENCODING_ASCII_US); rFileStream.ReadLine(aLine); - if( aLine.startsWith("Columns: ")) + if (std::string_view(aLine).starts_with("Columns: ")) rFileStream.ReadLine(aLine); // we can ignore this } else diff --git a/tools/source/stream/stream.cxx b/tools/source/stream/stream.cxx index d79a452cbade..16857b9c4145 100644 --- a/tools/source/stream/stream.cxx +++ b/tools/source/stream/stream.cxx @@ -378,7 +378,7 @@ void SvStream::ResetError() bool SvStream::ReadByteStringLine( OUString& rStr, rtl_TextEncoding eSrcCharSet, sal_Int32 nMaxBytesToRead ) { - OString aStr; + OStringBuffer aStr; bool bRet = ReadLine( aStr, nMaxBytesToRead); rStr = OStringToOUString(aStr, eSrcCharSet); return bRet; diff --git a/vcl/skia/SkiaHelper.cxx b/vcl/skia/SkiaHelper.cxx index 53de25ffcf86..941836d06e42 100644 --- a/vcl/skia/SkiaHelper.cxx +++ b/vcl/skia/SkiaHelper.cxx @@ -126,7 +126,7 @@ OUString readLog() SvFileStream logFile(getCacheFolder() + "/skia.log", StreamMode::READ); OUString sResult; - OString sLine; + OStringBuffer sLine; while (logFile.ReadLine(sLine)) sResult += OStringToOUString(sLine, RTL_TEXTENCODING_UTF8) + " ";