Kaydet (Commit) 4754b8ac authored tarafından Michael Meeks's avatar Michael Meeks

fastparser: avoid std::stack::top() - cache it's results.

amazingly std::stack::top() takes 146 pseudo-cycles to do not much,
so instead cache the result in a single pointer in lieu of burning
that code.

Change-Id: Ie326be47da6cbad0850e5f1026a1632bb840b6b8
üst 38f23632
...@@ -224,8 +224,8 @@ public: ...@@ -224,8 +224,8 @@ public:
void pushEntity( const Entity& rEntity ); void pushEntity( const Entity& rEntity );
void popEntity(); void popEntity();
Entity& getEntity(); Entity& getEntity() { return *mpTop; }
const Entity& getEntity() const; const Entity& getEntity() const { return *mpTop; }
void parse(); void parse();
void produce( CallbackType aType ); void produce( CallbackType aType );
...@@ -256,6 +256,8 @@ private: ...@@ -256,6 +256,8 @@ private:
NamespaceMap maNamespaceMap; NamespaceMap maNamespaceMap;
ParserData maData; /// Cached parser configuration for next call of parseStream(). ParserData maData; /// Cached parser configuration for next call of parseStream().
Entity *mpTop; /// std::stack::top() is amazingly slow => cache this.
::std::stack< Entity > maEntities; /// Entity stack for each call of parseStream(). ::std::stack< Entity > maEntities; /// Entity stack for each call of parseStream().
FastTokenLookup maTokenLookup; FastTokenLookup maTokenLookup;
}; };
...@@ -619,7 +621,9 @@ void Entity::saveException( const Exception &e ) ...@@ -619,7 +621,9 @@ void Entity::saveException( const Exception &e )
namespace sax_fastparser { namespace sax_fastparser {
FastSaxParserImpl::FastSaxParserImpl( FastSaxParser* pFront ) : mpFront(pFront) FastSaxParserImpl::FastSaxParserImpl( FastSaxParser* pFront ) :
mpFront(pFront),
mpTop(NULL)
{ {
mxDocumentLocator.set( new FastLocatorImpl( this ) ); mxDocumentLocator.set( new FastLocatorImpl( this ) );
} }
...@@ -1038,21 +1042,13 @@ bool FastSaxParserImpl::consume(EventList *pEventList) ...@@ -1038,21 +1042,13 @@ bool FastSaxParserImpl::consume(EventList *pEventList)
void FastSaxParserImpl::pushEntity( const Entity& rEntity ) void FastSaxParserImpl::pushEntity( const Entity& rEntity )
{ {
maEntities.push( rEntity ); maEntities.push( rEntity );
mpTop = &maEntities.top();
} }
void FastSaxParserImpl::popEntity() void FastSaxParserImpl::popEntity()
{ {
maEntities.pop(); maEntities.pop();
} mpTop = &maEntities.top();
Entity& FastSaxParserImpl::getEntity()
{
return maEntities.top();
}
const Entity& FastSaxParserImpl::getEntity() const
{
return maEntities.top();
} }
// starts parsing with actual parser ! // starts parsing with actual parser !
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment