include/unotools/tempfile.hxx          |    9 +++++++-
 unotools/source/ucbhelper/tempfile.cxx |   37 +++++++++++++++++++++++++++++++++
 2 files changed, 45 insertions(+), 1 deletion(-)

New commits:
commit 768d919f8fd91f4a82d663bbdff9cd03c596ab5f
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Fri Aug 16 09:43:46 2024 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Fri Aug 16 14:48:16 2024 +0200

    TempFileFastService should implement ByteReader/ByteWriter
    
    avoids some Sequence overhead in some hot paths
    
    Change-Id: I9d248cc088d423c8dc05895db934d6402c8baa44
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171946
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/include/unotools/tempfile.hxx b/include/unotools/tempfile.hxx
index db303a949f3a..fd257d359565 100644
--- a/include/unotools/tempfile.hxx
+++ b/include/unotools/tempfile.hxx
@@ -24,6 +24,7 @@
 #include <com/sun/star/io/XStream.hpp>
 #include <com/sun/star/io/XSeekable.hpp>
 #include <com/sun/star/io/XTruncate.hpp>
+#include <comphelper/bytereader.hxx>
 #include <cppuhelper/implbase.hxx>
 #include <tools/stream.hxx>
 #include <memory>
@@ -196,7 +197,8 @@ typedef ::cppu::WeakImplHelper<
     , css::io::XInputStream
     , css::io::XOutputStream
     , css::io::XTruncate> TempFileFastService_Base;
-class UNOTOOLS_DLLPUBLIC TempFileFastService final : public 
TempFileFastService_Base
+class UNOTOOLS_DLLPUBLIC TempFileFastService final : public 
TempFileFastService_Base,
+    public comphelper::ByteReader, public comphelper::ByteWriter
 {
     std::optional<utl::TempFileFast> mpTempFile;
     std::mutex maMutex;
@@ -231,6 +233,11 @@ public:
     // XTruncate
     SAL_DLLPRIVATE virtual void SAL_CALL truncate() override;
 
+    // comphelper::ByteReader
+    virtual sal_Int32 readSomeBytes(sal_Int8* aData, sal_Int32 nBytesToRead) 
override;
+    // comphelper::ByteWriter
+    virtual void writeBytes(const sal_Int8* aData, sal_Int32 nBytesToWrite) 
override;
+
 };
 
 
diff --git a/unotools/source/ucbhelper/tempfile.cxx 
b/unotools/source/ucbhelper/tempfile.cxx
index 26735035abbf..7862bc5f934d 100644
--- a/unotools/source/ucbhelper/tempfile.cxx
+++ b/unotools/source/ucbhelper/tempfile.cxx
@@ -569,6 +569,28 @@ sal_Int32 SAL_CALL TempFileFastService::readSomeBytes( 
css::uno::Sequence< sal_I
     return readBytes(aData, nMaxBytesToRead);
 }
 
+// comphelper::ByteReader
+sal_Int32 TempFileFastService::readSomeBytes( sal_Int8* aData, sal_Int32 
nBytesToRead )
+{
+    std::unique_lock aGuard( maMutex );
+    if ( mbInClosed )
+        throw css::io::NotConnectedException ( OUString(), getXWeak() );
+
+    checkConnected();
+    checkError();
+
+    if (nBytesToRead < 0)
+        throw css::io::BufferSizeExceededException( OUString(), getXWeak() );
+
+    if (mpStream->eof())
+        return 0;
+
+    sal_uInt32 nRead = mpStream->ReadBytes(aData, nBytesToRead);
+    checkError();
+
+    return nRead;
+}
+
 void SAL_CALL TempFileFastService::skipBytes( sal_Int32 nBytesToSkip )
 {
     std::unique_lock aGuard( maMutex );
@@ -626,6 +648,21 @@ void SAL_CALL TempFileFastService::writeBytes( const 
css::uno::Sequence< sal_Int
         throw css::io::BufferSizeExceededException( OUString(), getXWeak() );
 }
 
+// comphelper::ByteWriter
+
+void TempFileFastService::writeBytes( const sal_Int8* aData, sal_Int32 
nBytesToWrite )
+{
+    std::unique_lock aGuard( maMutex );
+    if ( mbOutClosed )
+        throw css::io::NotConnectedException ( OUString(), getXWeak() );
+
+    checkConnected();
+    sal_uInt32 nWritten = mpStream->WriteBytes(aData, nBytesToWrite);
+    checkError();
+    if  ( nWritten != o3tl::make_unsigned(nBytesToWrite) )
+        throw css::io::BufferSizeExceededException( OUString(), getXWeak() );
+}
+
 void SAL_CALL TempFileFastService::flush()
 {
     std::unique_lock aGuard( maMutex );

Reply via email to