fastparser: reuse event lists if possible
Instead of allocating and freeing the memory all the time. Change-Id: I53800abaca51d42d7d44a98fb271de7df7f90f58
This commit is contained in:
parent
902748b6ff
commit
6f1a110a37
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -149,6 +149,7 @@ struct Entity : public ParserData
|
||||
void startElement( Event *pEvent );
|
||||
void characters( const OUString& sChars );
|
||||
void endElement();
|
||||
EventList* getEventList();
|
||||
};
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
Loading…
x
Reference in New Issue
Block a user