fastparser: reuse event lists if possible
Instead of allocating and freeing the memory all the time. Change-Id: I53800abaca51d42d7d44a98fb271de7df7f90f58
This commit is contained in:
@@ -326,6 +326,28 @@ void Entity::endElement()
|
|||||||
}
|
}
|
||||||
maContextStack.pop();
|
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
|
// FastSaxParser implementation
|
||||||
// --------------------------------------------------------------------
|
// --------------------------------------------------------------------
|
||||||
@@ -774,15 +796,11 @@ void FastSaxParser::deleteUsedEvents()
|
|||||||
void FastSaxParser::produce(const Event& aEvent)
|
void FastSaxParser::produce(const Event& aEvent)
|
||||||
{
|
{
|
||||||
Entity& rEntity = getEntity();
|
Entity& rEntity = getEntity();
|
||||||
if (!rEntity.mpProducedEvents)
|
EventList* pEventList = rEntity.getEventList();
|
||||||
{
|
pEventList->push_back( aEvent );
|
||||||
rEntity.mpProducedEvents = new EventList();
|
if (aEvent.maType == CallbackType::DONE ||
|
||||||
rEntity.mpProducedEvents->reserve(rEntity.mnEventListSize);
|
aEvent.maType == CallbackType::EXCEPTION ||
|
||||||
}
|
pEventList->size() == rEntity.mnEventListSize)
|
||||||
rEntity.mpProducedEvents->push_back( aEvent );
|
|
||||||
if (aEvent->maType == CallbackType::DONE ||
|
|
||||||
aEvent->maType == CallbackType::EXCEPTION ||
|
|
||||||
rEntity.mpProducedEvents->size() == rEntity.mnEventListSize)
|
|
||||||
{
|
{
|
||||||
osl::ResettableMutexGuard aGuard(rEntity.maEventProtector);
|
osl::ResettableMutexGuard aGuard(rEntity.maEventProtector);
|
||||||
|
|
||||||
@@ -794,14 +812,12 @@ void FastSaxParser::produce(const Event& aEvent)
|
|||||||
aGuard.reset(); // lock
|
aGuard.reset(); // lock
|
||||||
}
|
}
|
||||||
|
|
||||||
rEntity.maPendingEvents.push(rEntity.mpProducedEvents);
|
rEntity.maPendingEvents.push(pEventList);
|
||||||
rEntity.mpProducedEvents = 0;
|
rEntity.mpProducedEvents = 0;
|
||||||
|
|
||||||
aGuard.clear(); // unlock
|
aGuard.clear(); // unlock
|
||||||
|
|
||||||
rEntity.maConsumeResume.set();
|
rEntity.maConsumeResume.set();
|
||||||
|
|
||||||
deleteUsedEvents();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -149,6 +149,7 @@ struct Entity : public ParserData
|
|||||||
void startElement( Event *pEvent );
|
void startElement( Event *pEvent );
|
||||||
void characters( const OUString& sChars );
|
void characters( const OUString& sChars );
|
||||||
void endElement();
|
void endElement();
|
||||||
|
EventList* getEventList();
|
||||||
};
|
};
|
||||||
|
|
||||||
// --------------------------------------------------------------------
|
// --------------------------------------------------------------------
|
||||||
|
Reference in New Issue
Block a user