diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2023-01-13 10:54:49 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2023-01-13 09:22:34 +0000 |
commit | 3de6b42235aa25f621ae293ad6bad1ee03298358 (patch) | |
tree | 55541bdb366225939aba70ea68bf34a3081c867f /package | |
parent | 8bdd832d2088af4f81402e2c0cb2ee36788238da (diff) |
Simplify a bit
Change-Id: Ie2435701078b0e111c1b04b77c857fd1923f2d59
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145430
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'package')
-rw-r--r-- | package/source/xstor/owriteablestream.cxx | 8 | ||||
-rw-r--r-- | package/source/zipapi/ZipFile.cxx | 42 |
2 files changed, 14 insertions, 36 deletions
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<XInputStream>& 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<sal_Int8> 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<sal_Int8> 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; } } |