diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2022-05-19 13:46:40 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2022-05-19 21:04:48 +0200 |
commit | 62531ec1091c7b3f6a3577889a18234790ec716d (patch) | |
tree | 72766dd4a58bbf61e2a56adc870d1a73307a9043 /include | |
parent | 5eb25f6a7ecb215f7bc81116cd930c1dec645e8d (diff) |
add ByteWriter to reduce memory copying when writing data
similarly to ByteReader
move both of them down to comphelper, since we want to use it from
comphelper, and comphelper is "below" unotools in the module dependency
graph
Change-Id: Ic98fa2268e125fd8e4378fb899ad5f97de721713
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134645
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'include')
-rw-r--r-- | include/comphelper/bytereader.hxx (renamed from include/unotools/bytereader.hxx) | 19 | ||||
-rw-r--r-- | include/comphelper/seqstream.hxx | 11 | ||||
-rw-r--r-- | include/unotools/streamwrap.hxx | 4 |
3 files changed, 28 insertions, 6 deletions
diff --git a/include/unotools/bytereader.hxx b/include/comphelper/bytereader.hxx index 8edf19929eea..a7e899098846 100644 --- a/include/unotools/bytereader.hxx +++ b/include/comphelper/bytereader.hxx @@ -8,16 +8,16 @@ */ #pragma once -#include <unotools/unotoolsdllapi.h> +#include <comphelper/comphelperdllapi.h> #include <com/sun/star/uno/Sequence.hxx> -namespace utl +namespace comphelper { /** * Interface that we can cast to, to bypass the inefficiency of using Sequence<sal_Int8> * when reading via XInputStream. */ -class UNOTOOLS_DLLPUBLIC ByteReader +class COMPHELPER_DLLPUBLIC ByteReader { public: virtual ~ByteReader(); @@ -26,6 +26,19 @@ public: static const css::uno::Sequence<sal_Int8>& getUnoTunnelId(); }; +/** + * Interface that we can cast to, to bypass the inefficiency of using Sequence<sal_Int8> + * when writing via XOutputStream. + */ +class COMPHELPER_DLLPUBLIC ByteWriter +{ +public: + virtual ~ByteWriter(); + virtual sal_Int32 writeSomeBytes(const sal_Int8* aData, sal_Int32 nBytesToWrite) = 0; + + static const css::uno::Sequence<sal_Int8>& getUnoTunnelId(); +}; + } // namespace utl /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/include/comphelper/seqstream.hxx b/include/comphelper/seqstream.hxx index 6cf22fdb6ebb..c2ba3913432b 100644 --- a/include/comphelper/seqstream.hxx +++ b/include/comphelper/seqstream.hxx @@ -24,8 +24,10 @@ #include <com/sun/star/io/XInputStream.hpp> #include <com/sun/star/io/XOutputStream.hpp> #include <com/sun/star/io/XSeekable.hpp> +#include <com/sun/star/lang/XUnoTunnel.hpp> #include <cppuhelper/implbase.hxx> #include <comphelper/comphelperdllapi.h> +#include <comphelper/bytereader.hxx> #include <mutex> namespace comphelper @@ -37,7 +39,8 @@ namespace comphelper class COMPHELPER_DLLPUBLIC SequenceInputStream final - : public ::cppu::WeakImplHelper< css::io::XInputStream, css::io::XSeekable > + : public ::cppu::WeakImplHelper< css::io::XInputStream, css::io::XSeekable, css::lang::XUnoTunnel >, + public comphelper::ByteReader { std::mutex m_aMutex; css::uno::Sequence<sal_Int8> const m_aData; @@ -61,6 +64,12 @@ public: virtual sal_Int64 SAL_CALL getPosition( ) override; virtual sal_Int64 SAL_CALL getLength( ) override; +// css::lang::XUnoTunnel + virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< sal_Int8 >& aIdentifier ) override; + +// comphelper::ByteReader + virtual sal_Int32 readSomeBytes( sal_Int8* pData, sal_Int32 nBytesToRead ) override; + private: sal_Int32 avail(); }; diff --git a/include/unotools/streamwrap.hxx b/include/unotools/streamwrap.hxx index 15e729f156f3..dc4c51807189 100644 --- a/include/unotools/streamwrap.hxx +++ b/include/unotools/streamwrap.hxx @@ -27,9 +27,9 @@ #include <com/sun/star/io/XTruncate.hpp> #include <com/sun/star/io/XStream.hpp> #include <com/sun/star/lang/XUnoTunnel.hpp> +#include <comphelper/bytereader.hxx> #include <cppuhelper/implbase.hxx> #include <cppuhelper/implbase1.hxx> -#include <unotools/bytereader.hxx> #include <memory> #include <mutex> @@ -42,7 +42,7 @@ namespace utl class SAL_DLLPUBLIC_TEMPLATE OInputStreamWrapper_Base : public cppu::WeakImplHelper< css::io::XInputStream, css::lang::XUnoTunnel > {}; /// helper class for wrapping an SvStream into a com.sun.star.io::XInputStream -class UNOTOOLS_DLLPUBLIC OInputStreamWrapper : public OInputStreamWrapper_Base, public ByteReader +class UNOTOOLS_DLLPUBLIC OInputStreamWrapper : public OInputStreamWrapper_Base, public comphelper::ByteReader { protected: std::mutex m_aMutex; |