diff options
author | Michael Meeks <michael.meeks@collabora.com> | 2013-11-26 16:26:12 +0000 |
---|---|---|
committer | Michael Meeks <michael.meeks@collabora.com> | 2013-11-26 17:33:44 +0000 |
commit | d7280af9740819971f46a855108334b84778b47d (patch) | |
tree | 12f13fe1c9afcaa2b2e4ab3a7d22a70bda710c23 /sax/source | |
parent | 2d681ad020d3cd6beb53a0de1c3057537f31c8df (diff) |
fastparser: Avoid copying all tokens into a sequence.
Diffstat (limited to 'sax/source')
-rw-r--r-- | sax/source/fastparser/fastparser.cxx | 14 | ||||
-rw-r--r-- | sax/source/fastparser/fastparser.hxx | 1 | ||||
-rw-r--r-- | sax/source/tools/fastattribs.cxx | 30 |
3 files changed, 22 insertions, 23 deletions
diff --git a/sax/source/fastparser/fastparser.cxx b/sax/source/fastparser/fastparser.cxx index 415747c63614..4c75e0cf6d8a 100644 --- a/sax/source/fastparser/fastparser.cxx +++ b/sax/source/fastparser/fastparser.cxx @@ -190,6 +190,7 @@ OUString SAL_CALL FastLocatorImpl::getSystemId(void) throw (RuntimeException) // -------------------------------------------------------------------- ParserData::ParserData() + : mpTokenHandler( NULL ) {} ParserData::~ParserData() @@ -382,7 +383,9 @@ void FastSaxParser::DefineNamespace( const OString& rPrefix, const sal_Char* pNa sal_Int32 FastSaxParser::GetToken( const sal_Char* pToken, sal_Int32 nLen /* = 0 */ ) { - return maTokenLookup.getTokenFromChars( getEntity().mxTokenHandler, pToken, nLen ); + return maTokenLookup.getTokenFromChars( getEntity().mxTokenHandler, + getEntity().mpTokenHandler, + pToken, nLen ); } // -------------------------------------------------------------------- @@ -623,9 +626,10 @@ void FastSaxParser::setFastDocumentHandler( const Reference< XFastDocumentHandle maData.mxDocumentHandler = Handler; } -void SAL_CALL FastSaxParser::setTokenHandler( const Reference< XFastTokenHandler >& Handler ) throw (RuntimeException) +void SAL_CALL FastSaxParser::setTokenHandler( const Reference< XFastTokenHandler >& xHandler ) throw (RuntimeException) { - maData.mxTokenHandler = Handler; + maData.mxTokenHandler = xHandler; + maData.mpTokenHandler = dynamic_cast< FastTokenHandlerBase *>( xHandler.get() ); } void SAL_CALL FastSaxParser::registerNamespace( const OUString& NamespaceURL, sal_Int32 NamespaceToken ) throw (IllegalArgumentException, RuntimeException) @@ -918,7 +922,9 @@ void FastSaxParser::callbackStartElement( const XML_Char* pwName, const XML_Char if (rEvent.mxAttributes.is()) rEvent.mxAttributes->clear(); else - rEvent.mxAttributes.set( new FastAttributeList( rEntity.mxTokenHandler ) ); + rEvent.mxAttributes.set( + new FastAttributeList( rEntity.mxTokenHandler, + rEntity.mpTokenHandler ) ); sal_Int32 nNameLen, nPrefixLen; const XML_Char *pName; diff --git a/sax/source/fastparser/fastparser.hxx b/sax/source/fastparser/fastparser.hxx index 35deb0c76b5e..d2bf1a73c354 100644 --- a/sax/source/fastparser/fastparser.hxx +++ b/sax/source/fastparser/fastparser.hxx @@ -92,6 +92,7 @@ struct ParserData { ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastDocumentHandler > mxDocumentHandler; ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastTokenHandler > mxTokenHandler; + FastTokenHandlerBase *mpTokenHandler; ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XErrorHandler > mxErrorHandler; ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XEntityResolver > mxEntityResolver; ::com::sun::star::lang::Locale maLocale; diff --git a/sax/source/tools/fastattribs.cxx b/sax/source/tools/fastattribs.cxx index ee65cc600c80..bc63b3eeeb2a 100644 --- a/sax/source/tools/fastattribs.cxx +++ b/sax/source/tools/fastattribs.cxx @@ -47,8 +47,10 @@ void UnknownAttribute::FillAttribute( Attribute* pAttrib ) const } } -FastAttributeList::FastAttributeList( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastTokenHandler >& xTokenHandler ) -: mxTokenHandler( xTokenHandler ) +FastAttributeList::FastAttributeList( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastTokenHandler >& xTokenHandler, + sax_fastparser::FastTokenHandlerBase *pTokenHandler) +: mxTokenHandler( xTokenHandler ), + mpTokenHandler( pTokenHandler ) { // random initial size of buffer to store attribute values mnChunkLength = 58; @@ -114,7 +116,7 @@ sal_Int32 FastAttributeList::getValueToken( ::sal_Int32 Token ) throw (SAXExcept { for (size_t i = 0; i < maAttributeTokens.size(); ++i) if (maAttributeTokens[i] == Token) - return maTokenLookup.getTokenFromChars( mxTokenHandler, + return maTokenLookup.getTokenFromChars( mxTokenHandler, mpTokenHandler, mpChunk + maAttributeValues[ i ], AttributeValueLength( i ) ); @@ -125,7 +127,7 @@ sal_Int32 FastAttributeList::getOptionalValueToken( ::sal_Int32 Token, ::sal_Int { for (size_t i = 0; i < maAttributeTokens.size(); ++i) if (maAttributeTokens[i] == Token) - return maTokenLookup.getTokenFromChars( mxTokenHandler, + return maTokenLookup.getTokenFromChars( mxTokenHandler, mpTokenHandler, mpChunk + maAttributeValues[ i ], AttributeValueLength( i ) ); @@ -227,6 +229,7 @@ FastTokenLookup::FastTokenLookup() */ sal_Int32 FastTokenLookup::getTokenFromChars( const ::css::uno::Reference< ::css::xml::sax::XFastTokenHandler > &xTokenHandler, + FastTokenHandlerBase *pTokenHandler, const char *pToken, size_t nLen /* = 0 */ ) { sal_Int32 nRet; @@ -234,23 +237,12 @@ sal_Int32 FastTokenLookup::getTokenFromChars( if( !nLen ) nLen = strlen( pToken ); - if ( static_cast<sal_Int32>(nLen) < mnUtf8BufferSize ) - { - // Get intimate 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 = xTokenHandler->getTokenFromUTF8( maUtf8Buffer ); - - (void)nPreRefCount; // for non-debug mode. - assert( pSeq->nRefCount == nPreRefCount ); // callee must not take ref - } + if( pTokenHandler ) + nRet = pTokenHandler->getTokenDirect( pToken, (sal_Int32) nLen ); else { - Sequence< sal_Int8 > aSeq( (sal_Int8*)pToken, nLen ); // heap allocate & free + // heap allocate, copy & then free + Sequence< sal_Int8 > aSeq( (sal_Int8*)pToken, nLen ); nRet = xTokenHandler->getTokenFromUTF8( aSeq ); } |