diff options
author | Michael Meeks <michael.meeks@collabora.com> | 2013-10-11 13:50:20 +0100 |
---|---|---|
committer | Michael Meeks <michael.meeks@collabora.com> | 2013-10-11 14:18:44 +0100 |
commit | f1702566befe8771210194d767dbea0022d0eae3 (patch) | |
tree | cfc62361bb0ce671b3182477e5ed0cc5e793fac7 /sax | |
parent | 0489d6b7d36dff230aa9f440ae54eb60c3643662 (diff) |
fastparser: don't allocate uno::Sequences when we don't need to.
Change-Id: Ic2fff8cabbc077b6fc9dabffd2c6fcf555152b11
Diffstat (limited to 'sax')
-rw-r--r-- | sax/source/fastparser/fastparser.cxx | 28 | ||||
-rw-r--r-- | sax/source/fastparser/fastparser.hxx | 3 |
2 files changed, 26 insertions, 5 deletions
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 }; } |