fastparser: don't allocate uno::Sequences when we don't need to.

Change-Id: Ic2fff8cabbc077b6fc9dabffd2c6fcf555152b11
This commit is contained in:
Michael Meeks
2013-10-11 13:50:20 +01:00
parent 0489d6b7d3
commit f1702566be
2 changed files with 26 additions and 5 deletions

View File

@@ -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();
return getEntity().mxTokenHandler->getTokenFromUTF8( aSeq );
sal_Int32 nPreRefCount = pSeq->nRefCount;
pSeq->nElements = nLen;
memcpy( pSeq->elements, pToken, nLen );
nRet = getEntity().mxTokenHandler->getTokenFromUTF8( maUtf8Buffer );
(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;
}
// --------------------------------------------------------------------

View File

@@ -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
};
}