sax/source/tools/CachedOutputStream.hxx |   10 ++++++----
 sax/source/tools/fastserializer.cxx     |   31 ++++++++++++++++++-------------
 sax/source/tools/fastserializer.hxx     |    9 +++++----
 3 files changed, 29 insertions(+), 21 deletions(-)

New commits:
commit 2373a13d4ce8f4308ee5de4d06140fc3b716ea29
Author:     Caolán McNamara <caolan.mcnam...@collabora.com>
AuthorDate: Wed Feb 5 14:20:59 2025 +0000
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Wed Feb 5 18:25:07 2025 +0100

    realloc-ing to 0 is common
    
    which frees, we can use a std::vector for this temp storage and
    avoid the reallocation churn.
    
    Change-Id: If7ea4ecb1e6c6a13934b5b9cc59fbb6c80180a42
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181186
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>

diff --git a/sax/source/tools/fastserializer.cxx 
b/sax/source/tools/fastserializer.cxx
index 47230fbc20b8..6a5ef7d48ba9 100644
--- a/sax/source/tools/fastserializer.cxx
+++ b/sax/source/tools/fastserializer.cxx
@@ -700,8 +700,8 @@ namespace sax_fastparser {
 
     Int8Sequence& FastSaxSerializer::ForMerge::getData()
     {
-        merge( maData, maPostponed, true );
-        maPostponed.realloc( 0 );
+        merge( maData, maPostponed.data(), maPostponed.size(), true );
+        maPostponed.resize(0);
 
         return maData;
     }
@@ -716,7 +716,7 @@ namespace sax_fastparser {
         }
 
         std::cerr << "
Postponed: ";
-        for ( sal_Int32 i=0, len=maPostponed.getLength(); i < len; i++ )
+        for ( sal_Int32 i=0, len=maPostponed.size(); i < len; i++ )
         {
             std::cerr << maPostponed[i];
         }
@@ -737,12 +737,12 @@ namespace sax_fastparser {
 
     void FastSaxSerializer::ForMerge::postpone( const Int8Sequence &rWhat )
     {
-        merge( maPostponed, rWhat, true );
+        const sal_Int8* pData = rWhat.getConstArray();
+        maPostponed.insert(maPostponed.end(), pData, pData + 
rWhat.getLength());
     }
 
-    void FastSaxSerializer::ForMerge::merge( Int8Sequence &rTop, const 
Int8Sequence &rMerge, bool bAppend )
+    void FastSaxSerializer::ForMerge::merge(Int8Sequence &rTop, const 
sal_Int8* pMerge, sal_Int32 nMergeLen, bool bAppend)
     {
-        sal_Int32 nMergeLen = rMerge.getLength();
         if ( nMergeLen <= 0 )
             return;
 
@@ -752,16 +752,21 @@ namespace sax_fastparser {
         if ( bAppend )
         {
             // append the rMerge to the rTop
-            memcpy( rTop.getArray() + nTopLen, rMerge.getConstArray(), 
nMergeLen );
+            memcpy( rTop.getArray() + nTopLen, pMerge, nMergeLen );
         }
         else
         {
             // prepend the rMerge to the rTop
             memmove( rTop.getArray() + nMergeLen, rTop.getConstArray(), 
nTopLen );
-            memcpy( rTop.getArray(), rMerge.getConstArray(), nMergeLen );
+            memcpy( rTop.getArray(), pMerge, nMergeLen );
         }
     }
 
+    void FastSaxSerializer::ForMerge::merge( Int8Sequence &rTop, const 
Int8Sequence &rMerge, bool bAppend )
+    {
+        merge(rTop, rMerge.getConstArray(), rMerge.getLength(), bAppend);
+    }
+
     void FastSaxSerializer::ForMerge::resetData( )
     {
         maData = Int8Sequence();
diff --git a/sax/source/tools/fastserializer.hxx 
b/sax/source/tools/fastserializer.hxx
index 3ed38d59b91c..fc5d6c838717 100644
--- a/sax/source/tools/fastserializer.hxx
+++ b/sax/source/tools/fastserializer.hxx
@@ -166,7 +166,7 @@ private:
     class ForMerge : public ForMergeBase
     {
         Int8Sequence maData;
-        Int8Sequence maPostponed;
+        std::vector<sal_Int8> maPostponed;
 
     public:
         sal_Int32 const m_Tag;
@@ -194,6 +194,8 @@ private:
     protected:
         void resetData( );
         static void merge( Int8Sequence &rTop, const Int8Sequence &rMerge, 
bool bAppend );
+    private:
+        static void merge( Int8Sequence &rTop, const sal_Int8* pMerge, 
sal_Int32 nMergeLen, bool bAppend );
     };
 
     class ForSort : public ForMerge
commit 796097c546c921b627f5e25f2a4f3d8bc0a6b37c
Author:     Caolán McNamara <caolan.mcnam...@collabora.com>
AuthorDate: Wed Feb 5 11:47:42 2025 +0000
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Wed Feb 5 18:24:54 2025 +0100

    use more ByteSequence in sax
    
    Change-Id: I514b022256acc60c20e430ef6e68815a47859ab6
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181185
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>
    Tested-by: Jenkins

diff --git a/sax/source/tools/CachedOutputStream.hxx 
b/sax/source/tools/CachedOutputStream.hxx
index 873ed51fe06a..77e21b1d417f 100644
--- a/sax/source/tools/CachedOutputStream.hxx
+++ b/sax/source/tools/CachedOutputStream.hxx
@@ -21,11 +21,13 @@
 
 namespace sax_fastparser {
 
+typedef rtl::ByteSequence Int8Sequence;
+
 class ForMergeBase
 {
 public:
     virtual ~ForMergeBase() {}
-    virtual void append( const css::uno::Sequence<sal_Int8>& rWhat ) = 0;
+    virtual void append( const Int8Sequence& rWhat ) = 0;
 };
 
 class CachedOutputStream
@@ -35,7 +37,7 @@ class CachedOutputStream
 
     /// ForMerge structure is used for sorting elements in Writer
     std::shared_ptr< ForMergeBase > mpForMerge;
-    const rtl::ByteSequence maCache;
+    const Int8Sequence maCache;
     /// Output stream, usually writing data into files.
     css::uno::Reference< css::io::XOutputStream > mxOutputStream;
     uno_Sequence *pSeq;
@@ -89,7 +91,7 @@ public:
                 if (mbWriteToOutStream)
                     mxOutputStream->writeBytes( 
css::uno::Sequence<sal_Int8>(pStr, nLen) );
                 else
-                    mpForMerge->append( css::uno::Sequence<sal_Int8>(pStr, 
nLen) );
+                    mpForMerge->append( Int8Sequence(pStr, nLen) );
                 return;
             }
         }
@@ -106,7 +108,7 @@ public:
         if (mbWriteToOutStream)
             mxOutputStream->writeBytes( css::uno::toUnoSequence(maCache) );
         else
-            mpForMerge->append( css::uno::toUnoSequence(maCache) );
+            mpForMerge->append( maCache );
         // and next time write to the beginning
         mnCacheWrittenSize = 0;
     }
diff --git a/sax/source/tools/fastserializer.cxx 
b/sax/source/tools/fastserializer.cxx
index ed1fbfafb4a0..47230fbc20b8 100644
--- a/sax/source/tools/fastserializer.cxx
+++ b/sax/source/tools/fastserializer.cxx
@@ -601,7 +601,7 @@ namespace sax_fastparser {
                 maMarkStack.top()->m_DebugStartedElements.pop_front();
             }
 #endif
-            Sequence<sal_Int8> aSeq( maMarkStack.top()->getData() );
+            Int8Sequence aSeq( maMarkStack.top()->getData() );
             maMarkStack.pop();
             mbMarkStackEmpty = true;
             maCachedOutputStream.resetOutputToStream();
@@ -698,7 +698,7 @@ namespace sax_fastparser {
         maCachedOutputStream.writeBytes( reinterpret_cast<const 
sal_Int8*>(pStr), nLen );
     }
 
-    FastSaxSerializer::Int8Sequence& FastSaxSerializer::ForMerge::getData()
+    Int8Sequence& FastSaxSerializer::ForMerge::getData()
     {
         merge( maData, maPostponed, true );
         maPostponed.realloc( 0 );
@@ -730,7 +730,7 @@ namespace sax_fastparser {
         merge( maData, rWhat, false );
     }
 
-    void FastSaxSerializer::ForMerge::append( const 
css::uno::Sequence<sal_Int8> &rWhat )
+    void FastSaxSerializer::ForMerge::append( const Int8Sequence &rWhat )
     {
         merge( maData, rWhat, true );
     }
@@ -783,7 +783,7 @@ namespace sax_fastparser {
         append( rWhat );
     }
 
-    void FastSaxSerializer::ForSort::append( const 
css::uno::Sequence<sal_Int8> &rWhat )
+    void FastSaxSerializer::ForSort::append( const Int8Sequence &rWhat )
     {
         merge( maData[mnCurrentElement], rWhat, true );
     }
@@ -803,7 +803,7 @@ namespace sax_fastparser {
         }
     }
 
-    FastSaxSerializer::Int8Sequence& FastSaxSerializer::ForSort::getData()
+    Int8Sequence& FastSaxSerializer::ForSort::getData()
     {
         sort( );
         return ForMerge::getData();
diff --git a/sax/source/tools/fastserializer.hxx 
b/sax/source/tools/fastserializer.hxx
index 8d97caf305a4..3ed38d59b91c 100644
--- a/sax/source/tools/fastserializer.hxx
+++ b/sax/source/tools/fastserializer.hxx
@@ -45,7 +45,6 @@ typedef std::vector<TokenValue> TokenValueList;
 /// Receives notification of sax document events to write into an 
XOutputStream.
 class FastSaxSerializer
 {
-    typedef css::uno::Sequence< ::sal_Int8 > Int8Sequence;
     typedef css::uno::Sequence< ::sal_Int32 > Int32Sequence;
 
 public:
@@ -189,7 +188,7 @@ private:
 #endif
 
         virtual void prepend( const Int8Sequence &rWhat );
-        virtual void append( const css::uno::Sequence<sal_Int8> &rWhat ) 
override;
+        virtual void append( const Int8Sequence &rWhat ) override;
         void postpone( const Int8Sequence &rWhat );
 
     protected:
@@ -220,7 +219,7 @@ private:
 #endif
 
         virtual void prepend( const Int8Sequence &rWhat ) override;
-        virtual void append( const css::uno::Sequence<sal_Int8> &rWhat ) 
override;
+        virtual void append( const Int8Sequence &rWhat ) override;
     private:
         void sort();
     };

Reply via email to