[Libreoffice-commits] core.git: 2 commits - package/inc package/source sax/source

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Thu Aug 12 07:33:04 UTC 2021


 package/inc/zipfileaccess.hxx               |    3 +-
 package/source/zippackage/zipfileaccess.cxx |    2 -
 sax/source/fastparser/fastparser.cxx        |   31 ++++++++++++++--------------
 3 files changed, 19 insertions(+), 17 deletions(-)

New commits:
commit 49f7d5cba44a14f168f26a9f1ade12618ff32d77
Author:     Noel Grandin <noelgrandin at gmail.com>
AuthorDate: Wed Aug 11 18:25:32 2021 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Thu Aug 12 09:32:30 2021 +0200

    flatten FastSaxParserImpl a little
    
    The EventList instances are movable (and are really just pointers
    to buffers of data), so no need to use unique_ptr
    
    Change-Id: Ic3e13e949f5a61ee9cc5fcf8da9e22094e8ab9da
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120342
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/sax/source/fastparser/fastparser.cxx b/sax/source/fastparser/fastparser.cxx
index 05a874cb3c33..2ffd008c6df6 100644
--- a/sax/source/fastparser/fastparser.cxx
+++ b/sax/source/fastparser/fastparser.cxx
@@ -150,9 +150,9 @@ struct Entity : public ParserData
 
     // Number of valid events in mxProducedEvents:
     size_t mnProducedEventsSize;
-    std::unique_ptr<EventList> mxProducedEvents;
-    std::queue<std::unique_ptr<EventList>> maPendingEvents;
-    std::queue<std::unique_ptr<EventList>> maUsedEvents;
+    std::optional<EventList> mxProducedEvents;
+    std::queue<EventList> maPendingEvents;
+    std::queue<EventList> maUsedEvents;
     osl::Mutex maEventProtector;
 
     static const size_t mnEventLowWater = 4;
@@ -548,7 +548,7 @@ EventList& Entity::getEventList()
         }
         if (!mxProducedEvents)
         {
-            mxProducedEvents.reset(new EventList);
+            mxProducedEvents.emplace();
             mxProducedEvents->maEvents.resize(mnEventListSize);
             mxProducedEvents->mbIsAttributesEmpty = false;
             mnProducedEventsSize = 0;
@@ -863,11 +863,11 @@ void FastSaxParserImpl::parseStream(const InputSource& rStructSource)
                 if (rEntity.maPendingEvents.size() <= Entity::mnEventLowWater)
                     rEntity.maProduceResume.set(); // start producer again
 
-                std::unique_ptr<EventList> xEventList = std::move(rEntity.maPendingEvents.front());
+                EventList aEventList = std::move(rEntity.maPendingEvents.front());
                 rEntity.maPendingEvents.pop();
                 aGuard.clear(); // unlock
 
-                if (!consume(*xEventList))
+                if (!consume(aEventList))
                     done = true;
 
                 aGuard.reset(); // lock
@@ -875,7 +875,7 @@ void FastSaxParserImpl::parseStream(const InputSource& rStructSource)
                 if ( rEntity.maPendingEvents.size() <= Entity::mnEventLowWater )
                 {
                     aGuard.clear();
-                    for (auto& rEvent : xEventList->maEvents)
+                    for (auto& rEvent : aEventList.maEvents)
                     {
                         if (rEvent.mxAttributes.is())
                         {
@@ -883,12 +883,12 @@ void FastSaxParserImpl::parseStream(const InputSource& rStructSource)
                             if( rEntity.mxNamespaceHandler.is() )
                                 rEvent.mxDeclAttributes->clear();
                         }
-                        xEventList->mbIsAttributesEmpty = true;
+                        aEventList.mbIsAttributesEmpty = true;
                     }
                     aGuard.reset();
                 }
 
-                rEntity.maUsedEvents.push(std::move(xEventList));
+                rEntity.maUsedEvents.push(std::move(aEventList));
             }
         } while (!done);
         aEnsureFree.joinThread();
@@ -978,12 +978,12 @@ void FastSaxParserImpl::deleteUsedEvents()
 
     while (!rEntity.maUsedEvents.empty())
     {
-        std::unique_ptr<EventList> xEventList = std::move(rEntity.maUsedEvents.front());
-        rEntity.maUsedEvents.pop();
+        { // the block makes sure that aEventList is destructed outside the lock
+            EventList aEventList = std::move(rEntity.maUsedEvents.front());
+            rEntity.maUsedEvents.pop();
 
-        aGuard.clear(); // unlock
-
-        xEventList.reset();
+            aGuard.clear(); // unlock
+        }
 
         aGuard.reset(); // lock
     }
@@ -1006,7 +1006,8 @@ void FastSaxParserImpl::produce( bool bForceFlush )
         aGuard.reset(); // lock
     }
 
-    rEntity.maPendingEvents.push(std::move(rEntity.mxProducedEvents));
+    rEntity.maPendingEvents.push(std::move(*rEntity.mxProducedEvents));
+    rEntity.mxProducedEvents.reset();
     assert(!rEntity.mxProducedEvents);
 
     aGuard.clear(); // unlock
commit 7bdb3a77d06664a500c2ed2f3464cd56647ce089
Author:     Noel Grandin <noelgrandin at gmail.com>
AuthorDate: Wed Aug 11 18:17:01 2021 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Thu Aug 12 09:32:10 2021 +0200

    flatten OZipFileAccess a little
    
    Change-Id: Ib03dadcd69a65493ddd9c0437fc654beef039ad8
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120341
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/package/inc/zipfileaccess.hxx b/package/inc/zipfileaccess.hxx
index a3f96346d6ec..b1ca8b1871bb 100644
--- a/package/inc/zipfileaccess.hxx
+++ b/package/inc/zipfileaccess.hxx
@@ -36,6 +36,7 @@
 #include "HashMaps.hxx"
 
 #include <memory>
+#include <optional>
 
 class OZipFileAccess final : public ::cppu::WeakImplHelper<
                         css::packages::zip::XZipFileAccess2,
@@ -46,7 +47,7 @@ class OZipFileAccess final : public ::cppu::WeakImplHelper<
     rtl::Reference<comphelper::RefCountedMutex> m_aMutexHolder;
     css::uno::Reference< css::uno::XComponentContext > m_xContext;
     css::uno::Reference< css::io::XInputStream > m_xContentStream;
-    std::unique_ptr<ZipFile> m_pZipFile;
+    std::optional<ZipFile> m_pZipFile;
     std::unique_ptr<::comphelper::OInterfaceContainerHelper2> m_pListenersContainer;
     bool m_bDisposed;
     bool m_bOwnContent;
diff --git a/package/source/zippackage/zipfileaccess.cxx b/package/source/zippackage/zipfileaccess.cxx
index 5e1afc0e345f..801a9fe79e54 100644
--- a/package/source/zippackage/zipfileaccess.cxx
+++ b/package/source/zippackage/zipfileaccess.cxx
@@ -240,7 +240,7 @@ void SAL_CALL OZipFileAccess::initialize( const uno::Sequence< uno::Any >& aArgu
     }
 
     // TODO: in case xSeekable is implemented on separated XStream implementation a wrapper is required
-    m_pZipFile = std::make_unique<ZipFile>(
+    m_pZipFile.emplace(
                 m_aMutexHolder,
                 m_xContentStream,
                 m_xContext,


More information about the Libreoffice-commits mailing list