From 3de6b42235aa25f621ae293ad6bad1ee03298358 Mon Sep 17 00:00:00 2001 From: Mike Kaganski Date: Fri, 13 Jan 2023 10:54:49 +0300 Subject: Simplify a bit Change-Id: Ie2435701078b0e111c1b04b77c857fd1923f2d59 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145430 Tested-by: Jenkins Reviewed-by: Mike Kaganski --- package/source/xstor/owriteablestream.cxx | 8 ++---- package/source/zipapi/ZipFile.cxx | 42 +++++++++---------------------- 2 files changed, 14 insertions(+), 36 deletions(-) (limited to 'package') diff --git a/package/source/xstor/owriteablestream.cxx b/package/source/xstor/owriteablestream.cxx index 88d85c9fc5d2..72792e21fcb9 100644 --- a/package/source/xstor/owriteablestream.cxx +++ b/package/source/xstor/owriteablestream.cxx @@ -90,9 +90,7 @@ static void CopyInputToOutput( { static const sal_Int32 nConstBufferSize = 32000; - comphelper::ByteReader* pByteReader = dynamic_cast< comphelper::ByteReader* >( xInput.get() ); - - if (pByteReader) + if (auto pByteReader = dynamic_cast< comphelper::ByteReader* >( xInput.get() )) { sal_Int32 nRead; sal_Int8 aTempBuf[ nConstBufferSize ]; @@ -2155,9 +2153,7 @@ void OWriteStream::writeBytes( const sal_Int8* pData, sal_Int32 nBytesToWrite ) if ( !m_xOutStream.is() ) throw io::NotConnectedException(); - uno::Reference< css::lang::XUnoTunnel > xOutputTunnel( m_xOutStream, uno::UNO_QUERY ); - comphelper::ByteWriter* pByteWriter = dynamic_cast< comphelper::ByteWriter* >( m_xOutStream.get() ); - if (pByteWriter) + if (auto pByteWriter = dynamic_cast< comphelper::ByteWriter* >( m_xOutStream.get() )) pByteWriter->writeBytes(pData, nBytesToWrite); else { diff --git a/package/source/zipapi/ZipFile.cxx b/package/source/zipapi/ZipFile.cxx index f839590f0be3..42e1972d1d07 100644 --- a/package/source/zipapi/ZipFile.cxx +++ b/package/source/zipapi/ZipFile.cxx @@ -548,9 +548,9 @@ public: XBufferedStream( const uno::Reference& xSrcStream ) : mnPos(0) { sal_Int32 nRemaining = xSrcStream->available(); - comphelper::ByteReader* pByteReader = dynamic_cast< comphelper::ByteReader* >( xSrcStream.get() ); + maBytes.reserve(nRemaining); - if (pByteReader) + if (auto pByteReader = dynamic_cast< comphelper::ByteReader* >( xSrcStream.get() )) { maBytes.resize(nRemaining); @@ -561,36 +561,18 @@ public: nRemaining -= nRead; pData += nRead; } + return; } - else - { - const sal_Int32 nBufSize = 8192; - sal_Int32 nRead = 0; - maBytes.reserve(nRemaining); - uno::Sequence aBuf(nBufSize); - - auto readAndCopy = [&]( sal_Int32 nReadSize ) -> sal_Int32 - { - sal_Int32 nBytes = xSrcStream->readBytes(aBuf, nReadSize); - const sal_Int8* p = aBuf.getConstArray(); - const sal_Int8* pEnd = p + nBytes; - maBytes.insert( maBytes.end(), p, pEnd ); - return nBytes; - }; - - while (nRemaining > nBufSize) - { - const auto nBytes = readAndCopy(nBufSize); - if (!nBytes) - break; - nRead += nBytes; - nRemaining -= nBytes; - } - - if (nRemaining) - nRead += readAndCopy(nRemaining); - maBytes.resize(nRead); + const sal_Int32 nBufSize = 8192; + uno::Sequence aBuf(nBufSize); + while (nRemaining > 0) + { + const sal_Int32 nBytes = xSrcStream->readBytes(aBuf, std::min(nBufSize, nRemaining)); + if (!nBytes) + break; + maBytes.insert(maBytes.end(), aBuf.begin(), aBuf.begin() + nBytes); + nRemaining -= nBytes; } } -- cgit