diff options
author | Matúš Kukan <matus.kukan@gmail.com> | 2013-10-15 10:32:55 +0200 |
---|---|---|
committer | Matúš Kukan <matus.kukan@gmail.com> | 2013-10-17 21:38:38 +0200 |
commit | 6f1a110a370967b31f46d0323329dd9b4436ea26 (patch) | |
tree | 788e68f426bc3d7963a98583001bf2ab4065de7e /sax | |
parent | 902748b6ff9aca0793466c863e30c9e052321f52 (diff) |
fastparser: reuse event lists if possible
Instead of allocating and freeing the memory all the time.
Change-Id: I53800abaca51d42d7d44a98fb271de7df7f90f58
Diffstat (limited to 'sax')
-rw-r--r-- | sax/source/fastparser/fastparser.cxx | 40 | ||||
-rw-r--r-- | 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(); }; // -------------------------------------------------------------------- |