summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--comphelper/source/misc/storagehelper.cxx48
-rw-r--r--package/source/xstor/owriteablestream.cxx8
-rw-r--r--package/source/zipapi/ZipFile.cxx42
3 files changed, 34 insertions, 64 deletions
diff --git a/comphelper/source/misc/storagehelper.cxx b/comphelper/source/misc/storagehelper.cxx
index 7b41eafbf9f1..3fdabfcfe430 100644
--- a/comphelper/source/misc/storagehelper.cxx
+++ b/comphelper/source/misc/storagehelper.cxx
@@ -175,40 +175,32 @@ void OStorageHelper::CopyInputToOutput(
{
static const sal_Int32 nConstBufferSize = 32000;
- comphelper::ByteReader* pByteReader = dynamic_cast< comphelper::ByteReader* >( xInput.get() );
- comphelper::ByteWriter* pByteWriter = nullptr;
- if (pByteReader)
- pByteWriter = dynamic_cast< comphelper::ByteWriter* >( xOutput.get() );
-
- if (pByteWriter)
- {
- sal_Int32 nRead;
- sal_Int8 aTempBuf[ nConstBufferSize ];
- do
- {
- nRead = pByteReader->readSomeBytes ( aTempBuf, nConstBufferSize );
- pByteWriter->writeBytes ( aTempBuf, nRead );
- }
- while ( nRead == nConstBufferSize );
- }
- else
+ if (auto pByteReader = dynamic_cast< comphelper::ByteReader* >( xInput.get() ))
{
- sal_Int32 nRead;
- uno::Sequence < sal_Int8 > aSequence ( nConstBufferSize );
-
- do
+ if (auto pByteWriter = dynamic_cast< comphelper::ByteWriter* >( xOutput.get() ))
{
- nRead = xInput->readBytes ( aSequence, nConstBufferSize );
- if ( nRead < nConstBufferSize )
+ sal_Int32 nRead;
+ sal_Int8 aTempBuf[ nConstBufferSize ];
+ do
{
- uno::Sequence < sal_Int8 > aTempBuf ( aSequence.getConstArray(), nRead );
- xOutput->writeBytes ( aTempBuf );
+ nRead = pByteReader->readSomeBytes ( aTempBuf, nConstBufferSize );
+ pByteWriter->writeBytes ( aTempBuf, nRead );
}
- else
- xOutput->writeBytes ( aSequence );
+ while ( nRead == nConstBufferSize );
+ return;
}
- while ( nRead == nConstBufferSize );
}
+
+ sal_Int32 nRead;
+ uno::Sequence < sal_Int8 > aSequence ( nConstBufferSize );
+ do
+ {
+ nRead = xInput->readBytes ( aSequence, nConstBufferSize );
+ if ( nRead < nConstBufferSize )
+ aSequence.realloc( nRead );
+ xOutput->writeBytes ( aSequence );
+ }
+ while ( nRead == nConstBufferSize );
}
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;
}
}