From f1702566befe8771210194d767dbea0022d0eae3 Mon Sep 17 00:00:00 2001 From: Michael Meeks Date: Fri, 11 Oct 2013 13:50:20 +0100 Subject: fastparser: don't allocate uno::Sequences when we don't need to. Change-Id: Ic2fff8cabbc077b6fc9dabffd2c6fcf555152b11 --- sax/source/fastparser/fastparser.cxx | 28 +++++++++++++++++++++++----- sax/source/fastparser/fastparser.hxx | 3 +++ 2 files changed, 26 insertions(+), 5 deletions(-) (limited to 'sax') diff --git a/sax/source/fastparser/fastparser.cxx b/sax/source/fastparser/fastparser.cxx index 34779968fd4b..6b793db1793e 100644 --- a/sax/source/fastparser/fastparser.cxx +++ b/sax/source/fastparser/fastparser.cxx @@ -201,6 +201,7 @@ Entity::~Entity() FastSaxParser::FastSaxParser() { mxDocumentLocator.set( new FastLocatorImpl( this ) ); + maUtf8Buffer.realloc( mnUtf8BufferSize ); } // -------------------------------------------------------------------- @@ -259,19 +260,36 @@ void FastSaxParser::DefineNamespace( const OString& rPrefix, const sal_Char* pNa sal_Int32 FastSaxParser::GetToken( const OString& rToken ) { - Sequence< sal_Int8 > aSeq( (sal_Int8*)rToken.getStr(), rToken.getLength() ); - - return getEntity().mxTokenHandler->getTokenFromUTF8( aSeq ); + return GetToken( rToken.getStr(), rToken.getLength() ); } sal_Int32 FastSaxParser::GetToken( const sal_Char* pToken, sal_Int32 nLen /* = 0 */ ) { + sal_Int32 nRet; + if( !nLen ) nLen = strlen( pToken ); - Sequence< sal_Int8 > aSeq( (sal_Int8*)pToken, nLen ); + if ( nLen < mnUtf8BufferSize ) + { + // Get intimiate with the underlying sequence cf. sal/types.h + sal_Sequence *pSeq = maUtf8Buffer.get(); + + sal_Int32 nPreRefCount = pSeq->nRefCount; + + pSeq->nElements = nLen; + memcpy( pSeq->elements, pToken, nLen ); + nRet = getEntity().mxTokenHandler->getTokenFromUTF8( maUtf8Buffer ); - return getEntity().mxTokenHandler->getTokenFromUTF8( aSeq ); + (void)nPreRefCount; // for non-debug mode. + assert( pSeq->nRefCount == nPreRefCount ); // callee must not take ref. + } + else + { + Sequence< sal_Int8 > aSeq( (sal_Int8*)pToken, nLen ); // heap allocate & free + nRet = getEntity().mxTokenHandler->getTokenFromUTF8( aSeq ); + } + return nRet; } // -------------------------------------------------------------------- diff --git a/sax/source/fastparser/fastparser.hxx b/sax/source/fastparser/fastparser.hxx index dab438f81422..e75ee0f0a596 100644 --- a/sax/source/fastparser/fastparser.hxx +++ b/sax/source/fastparser/fastparser.hxx @@ -154,6 +154,9 @@ private: ParserData maData; /// Cached parser configuration for next call of parseStream(). ::std::stack< Entity > maEntities; /// Entity stack for each call of parseStream(). + + static const int mnUtf8BufferSize = 128; + ::css::uno::Sequence< sal_Int8 > maUtf8Buffer; /// avoid constantly re-allocating this }; } -- cgit