From 16a38eb854d2303e9a723651c3ab66897efe03d0 Mon Sep 17 00:00:00 2001 From: Michael Meeks Date: Tue, 26 Nov 2013 16:26:12 +0000 Subject: fastparser: Avoid copying all tokens into a sequence. --- .../source/ooxml/OOXMLFastTokenHandler.cxx | 23 +++++++++++----------- .../source/ooxml/OOXMLFastTokenHandler.hxx | 7 ++++++- 2 files changed, 18 insertions(+), 12 deletions(-) (limited to 'writerfilter/source') diff --git a/writerfilter/source/ooxml/OOXMLFastTokenHandler.cxx b/writerfilter/source/ooxml/OOXMLFastTokenHandler.cxx index 096de7f0b9c1..4cf32f562a27 100644 --- a/writerfilter/source/ooxml/OOXMLFastTokenHandler.cxx +++ b/writerfilter/source/ooxml/OOXMLFastTokenHandler.cxx @@ -108,23 +108,16 @@ css::uno::Sequence< ::sal_Int8 > SAL_CALL OOXMLFastTokenHandler::getUTF8Identifi #endif } -::sal_Int32 SAL_CALL OOXMLFastTokenHandler::getTokenFromUTF8 -(const css::uno::Sequence< ::sal_Int8 > & Identifier) throw (css::uno::RuntimeException) +::sal_Int32 SAL_CALL OOXMLFastTokenHandler::getTokenDirect( const char *pStr, sal_Int32 nLength ) const { - ::sal_Int32 nResult = OOXML_FAST_TOKENS_END; - struct tokenmap::token * pToken = - tokenmap::Perfect_Hash::in_word_set - (reinterpret_cast(Identifier.getConstArray()), - Identifier.getLength()); + tokenmap::Perfect_Hash::in_word_set( pStr, nLength ); - if (pToken != NULL) - nResult = pToken->nToken; + sal_Int32 nResult = pToken != NULL ? pToken->nToken : OOXML_FAST_TOKENS_END; #ifdef DEBUG_TOKEN clog << "getTokenFromUTF8: " - << string(reinterpret_cast - (Identifier.getConstArray()), Identifier.getLength()) + << string(pStr, nLength) << ", " << nResult << (pToken == NULL ? ", failed" : "") << endl; #endif @@ -132,6 +125,14 @@ css::uno::Sequence< ::sal_Int8 > SAL_CALL OOXMLFastTokenHandler::getUTF8Identifi return nResult; } +::sal_Int32 SAL_CALL OOXMLFastTokenHandler::getTokenFromUTF8 +(const css::uno::Sequence< ::sal_Int8 > & Identifier) throw (css::uno::RuntimeException) +{ + return getTokenDirect(reinterpret_cast + (Identifier.getConstArray()), + Identifier.getLength()); +} + }} /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/ooxml/OOXMLFastTokenHandler.hxx b/writerfilter/source/ooxml/OOXMLFastTokenHandler.hxx index 120c4e70a74f..ddb5b50d153a 100644 --- a/writerfilter/source/ooxml/OOXMLFastTokenHandler.hxx +++ b/writerfilter/source/ooxml/OOXMLFastTokenHandler.hxx @@ -24,6 +24,7 @@ #include "com/sun/star/uno/XComponentContext.hpp" #include "cppuhelper/implbase1.hxx" #include "com/sun/star/xml/sax/XFastTokenHandler.hpp" +#include "sax/fastattribs.hxx" namespace writerfilter { namespace ooxml @@ -31,7 +32,8 @@ namespace ooxml class OOXMLFastTokenHandler: public ::cppu::WeakImplHelper1< - css::xml::sax::XFastTokenHandler> + css::xml::sax::XFastTokenHandler>, + public sax_fastparser::FastTokenHandlerBase { public: explicit OOXMLFastTokenHandler(css::uno::Reference< css::uno::XComponentContext > const & context); @@ -42,6 +44,9 @@ public: virtual css::uno::Sequence< ::sal_Int8 > SAL_CALL getUTF8Identifier(::sal_Int32 Token) throw (css::uno::RuntimeException); virtual ::sal_Int32 SAL_CALL getTokenFromUTF8(const css::uno::Sequence< ::sal_Int8 > & Identifier) throw (css::uno::RuntimeException); + // Much faster direct C++ shortcut to the method that matters + virtual sal_Int32 getTokenDirect( const char *pToken, sal_Int32 nLength ) const; + private: OOXMLFastTokenHandler(OOXMLFastTokenHandler &); // not defined void operator =(OOXMLFastTokenHandler &); // not defined -- cgit v1.2.3