diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2024-08-17 13:19:54 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2024-08-27 09:10:04 +0200 |
commit | a6ad198d097fb4a503c8d5831d484ff46721134b (patch) | |
tree | e82ca01e800c5f50ce8db7bd8eb610790ee13c8d /package/source/zipapi/XBufferedThreadedStream.cxx | |
parent | 03b31a8ad48e3b8a9e54203ff3856702557757b5 (diff) |
tdf#158556 use more comphelper::ByteReader
which avoids a ton of temporary uno::Sequence being created
Change-Id: I237bb69395f692bb0272ca0daec05b81af828e01
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171968
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Tested-by: Jenkins
Diffstat (limited to 'package/source/zipapi/XBufferedThreadedStream.cxx')
-rw-r--r-- | package/source/zipapi/XBufferedThreadedStream.cxx | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/package/source/zipapi/XBufferedThreadedStream.cxx b/package/source/zipapi/XBufferedThreadedStream.cxx index d3bf995d9073..ea7c270ebea6 100644 --- a/package/source/zipapi/XBufferedThreadedStream.cxx +++ b/package/source/zipapi/XBufferedThreadedStream.cxx @@ -158,6 +158,32 @@ sal_Int32 SAL_CALL XBufferedThreadedStream::readBytes( Sequence< sal_Int8 >& rDa return nAvailableSize; } +sal_Int32 XBufferedThreadedStream::readSomeBytes( sal_Int8* pData, sal_Int32 nBytesToRead ) +{ + if( !hasBytes() ) + return 0; + + const sal_Int32 nAvailableSize = static_cast< sal_Int32 > ( std::min< sal_Int64 >( nBytesToRead, remainingSize() ) ); + sal_Int32 i = 0, nPendingBytes = nAvailableSize; + + while( nPendingBytes ) + { + const Buffer &pBuffer = getNextBlock(); + if( !pBuffer.hasElements() ) + return nAvailableSize - nPendingBytes; + const sal_Int32 limit = std::min<sal_Int32>( nPendingBytes, pBuffer.getLength() - mnOffset ); + + memcpy( &pData[i], &pBuffer[mnOffset], limit ); + + nPendingBytes -= limit; + mnOffset += limit; + mnPos += limit; + i += limit; + } + + return nAvailableSize; +} + sal_Int32 SAL_CALL XBufferedThreadedStream::readSomeBytes( Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead ) { return readBytes( aData, nMaxBytesToRead ); |