summaryrefslogtreecommitdiff
path: root/comphelper/source
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2024-08-17 13:19:54 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2024-08-27 09:10:04 +0200
commita6ad198d097fb4a503c8d5831d484ff46721134b (patch)
treee82ca01e800c5f50ce8db7bd8eb610790ee13c8d /comphelper/source
parent03b31a8ad48e3b8a9e54203ff3856702557757b5 (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 'comphelper/source')
-rw-r--r--comphelper/source/streaming/memorystream.cxx25
-rw-r--r--comphelper/source/streaming/seekableinput.cxx17
2 files changed, 41 insertions, 1 deletions
diff --git a/comphelper/source/streaming/memorystream.cxx b/comphelper/source/streaming/memorystream.cxx
index b457f4b42ca8..39ae66b51d07 100644
--- a/comphelper/source/streaming/memorystream.cxx
+++ b/comphelper/source/streaming/memorystream.cxx
@@ -55,7 +55,7 @@ namespace {
class UNOMemoryStream :
public WeakImplHelper<XServiceInfo, XStream, XSeekableInputStream, XOutputStream, XTruncate>,
- public comphelper::ByteWriter
+ public comphelper::ByteWriter, public comphelper::ByteReader
{
public:
UNOMemoryStream();
@@ -92,6 +92,9 @@ public:
// comphelper::ByteWriter
virtual void writeBytes(const sal_Int8* aData, sal_Int32 nBytesToWrite) override;
+ // comphelper::ByteReader
+ virtual sal_Int32 readSomeBytes(sal_Int8* aData, sal_Int32 nBytesToRead) override;
+
private:
std::vector< sal_Int8, boost::noinit_adaptor<std::allocator<sal_Int8>> > maData;
sal_Int32 mnCursor;
@@ -153,6 +156,26 @@ sal_Int32 SAL_CALL UNOMemoryStream::readBytes( Sequence< sal_Int8 >& aData, sal_
return nBytesToRead;
}
+// ByteReader
+sal_Int32 UNOMemoryStream::readSomeBytes( sal_Int8* aData, sal_Int32 nBytesToRead )
+{
+ if( nBytesToRead < 0 )
+ throw IOException(u"nBytesToRead < 0"_ustr);
+
+ nBytesToRead = std::min( nBytesToRead, available() );
+
+ if( nBytesToRead )
+ {
+ sal_Int8* pData = &(*maData.begin());
+ sal_Int8* pCursor = &(pData[mnCursor]);
+ memcpy( aData, pCursor, nBytesToRead );
+
+ mnCursor += nBytesToRead;
+ }
+
+ return nBytesToRead;
+}
+
sal_Int32 SAL_CALL UNOMemoryStream::readSomeBytes( Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead )
{
return readBytes( aData, nMaxBytesToRead );
diff --git a/comphelper/source/streaming/seekableinput.cxx b/comphelper/source/streaming/seekableinput.cxx
index 6fd418df36ca..dceb16824c58 100644
--- a/comphelper/source/streaming/seekableinput.cxx
+++ b/comphelper/source/streaming/seekableinput.cxx
@@ -107,7 +107,11 @@ void OSeekableInputWrapper::PrepareCopy_Impl()
xTempSeek->seek( 0 );
m_xCopyInput.set( xTempOut, uno::UNO_QUERY );
if ( m_xCopyInput.is() )
+ {
m_xCopySeek = xTempSeek;
+ m_pCopyByteReader = dynamic_cast<comphelper::ByteReader*>(xTempOut.get());
+ assert(m_pCopyByteReader);
+ }
}
}
@@ -142,6 +146,18 @@ sal_Int32 SAL_CALL OSeekableInputWrapper::readSomeBytes( uno::Sequence< sal_Int8
return m_xCopyInput->readSomeBytes( aData, nMaxBytesToRead );
}
+sal_Int32 OSeekableInputWrapper::readSomeBytes( sal_Int8* aData, sal_Int32 nMaxBytesToRead )
+{
+ std::scoped_lock aGuard( m_aMutex );
+
+ if ( !m_xOriginalStream.is() )
+ throw io::NotConnectedException();
+
+ PrepareCopy_Impl();
+
+ return m_pCopyByteReader->readSomeBytes( aData, nMaxBytesToRead );
+}
+
void SAL_CALL OSeekableInputWrapper::skipBytes( sal_Int32 nBytesToSkip )
{
@@ -186,6 +202,7 @@ void SAL_CALL OSeekableInputWrapper::closeInput()
}
m_xCopySeek.clear();
+ m_pCopyByteReader = nullptr;
}