From 49f7d5cba44a14f168f26a9f1ade12618ff32d77 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Wed, 11 Aug 2021 18:25:32 +0200 Subject: 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 --- sax/source/fastparser/fastparser.cxx | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) (limited to 'sax/source/fastparser') 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 mxProducedEvents; - std::queue> maPendingEvents; - std::queue> maUsedEvents; + std::optional mxProducedEvents; + std::queue maPendingEvents; + std::queue 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 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 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 -- cgit