diff options
author | Noel Grandin <noelgrandin@gmail.com> | 2021-08-11 18:25:32 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-08-12 09:32:30 +0200 |
commit | 49f7d5cba44a14f168f26a9f1ade12618ff32d77 (patch) | |
tree | adfe46ae1eac46823740e418ce8dcae59b072e8e /sax/source/fastparser/fastparser.cxx | |
parent | 7bdb3a77d06664a500c2ed2f3464cd56647ce089 (diff) |
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@collabora.co.uk>
Diffstat (limited to 'sax/source/fastparser/fastparser.cxx')
-rw-r--r-- | sax/source/fastparser/fastparser.cxx | 31 |
1 files changed, 16 insertions, 15 deletions
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 |