From 6f1a110a370967b31f46d0323329dd9b4436ea26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=BA=C5=A1=20Kukan?= Date: Tue, 15 Oct 2013 10:32:55 +0200 Subject: [PATCH] fastparser: reuse event lists if possible Instead of allocating and freeing the memory all the time. Change-Id: I53800abaca51d42d7d44a98fb271de7df7f90f58 --- sax/source/fastparser/fastparser.cxx | 40 +++++++++++++++++++--------- sax/source/fastparser/fastparser.hxx | 1 + 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/sax/source/fastparser/fastparser.cxx b/sax/source/fastparser/fastparser.cxx index 2040c32a1ed8..8748ee4fb93a 100644 --- a/sax/source/fastparser/fastparser.cxx +++ b/sax/source/fastparser/fastparser.cxx @@ -326,6 +326,28 @@ void Entity::endElement() } maContextStack.pop(); } + +EventList* Entity::getEventList() +{ + if (!mpProducedEvents) + { + osl::ResettableMutexGuard aGuard(maEventProtector); + if (!maUsedEvents.empty()) + { + mpProducedEvents = maUsedEvents.front(); + maUsedEvents.pop(); + aGuard.clear(); // unlock + mpProducedEvents->clear(); + } + if (!mpProducedEvents) + { + mpProducedEvents = new EventList(); + mpProducedEvents->reserve(mnEventListSize); + } + } + return mpProducedEvents; +} + // -------------------------------------------------------------------- // FastSaxParser implementation // -------------------------------------------------------------------- @@ -774,15 +796,11 @@ void FastSaxParser::deleteUsedEvents() void FastSaxParser::produce(const Event& aEvent) { Entity& rEntity = getEntity(); - if (!rEntity.mpProducedEvents) - { - rEntity.mpProducedEvents = new EventList(); - rEntity.mpProducedEvents->reserve(rEntity.mnEventListSize); - } - rEntity.mpProducedEvents->push_back( aEvent ); - if (aEvent->maType == CallbackType::DONE || - aEvent->maType == CallbackType::EXCEPTION || - rEntity.mpProducedEvents->size() == rEntity.mnEventListSize) + EventList* pEventList = rEntity.getEventList(); + pEventList->push_back( aEvent ); + if (aEvent.maType == CallbackType::DONE || + aEvent.maType == CallbackType::EXCEPTION || + pEventList->size() == rEntity.mnEventListSize) { osl::ResettableMutexGuard aGuard(rEntity.maEventProtector); @@ -794,14 +812,12 @@ void FastSaxParser::produce(const Event& aEvent) aGuard.reset(); // lock } - rEntity.maPendingEvents.push(rEntity.mpProducedEvents); + rEntity.maPendingEvents.push(pEventList); rEntity.mpProducedEvents = 0; aGuard.clear(); // unlock rEntity.maConsumeResume.set(); - - deleteUsedEvents(); } } diff --git a/sax/source/fastparser/fastparser.hxx b/sax/source/fastparser/fastparser.hxx index 88d6a223d0f9..3f7fb34bec38 100644 --- a/sax/source/fastparser/fastparser.hxx +++ b/sax/source/fastparser/fastparser.hxx @@ -149,6 +149,7 @@ struct Entity : public ParserData void startElement( Event *pEvent ); void characters( const OUString& sChars ); void endElement(); + EventList* getEventList(); }; // --------------------------------------------------------------------