summaryrefslogtreecommitdiff
path: root/include/oox
diff options
context:
space:
mode:
authorMichael Meeks <michael.meeks@collabora.com>2013-11-26 16:26:12 +0000
committerMichael Meeks <michael.meeks@collabora.com>2013-11-26 17:33:44 +0000
commitd7280af9740819971f46a855108334b84778b47d (patch)
tree12f13fe1c9afcaa2b2e4ab3a7d22a70bda710c23 /include/oox
parent2d681ad020d3cd6beb53a0de1c3057537f31c8df (diff)
fastparser: Avoid copying all tokens into a sequence.
Diffstat (limited to 'include/oox')
-rw-r--r--include/oox/core/fasttokenhandler.hxx7
-rw-r--r--include/oox/token/tokenmap.hxx22
2 files changed, 27 insertions, 2 deletions
diff --git a/include/oox/core/fasttokenhandler.hxx b/include/oox/core/fasttokenhandler.hxx
index b79472c7e466..fb4e0e16fac6 100644
--- a/include/oox/core/fasttokenhandler.hxx
+++ b/include/oox/core/fasttokenhandler.hxx
@@ -23,6 +23,7 @@
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/xml/sax/XFastTokenHandler.hpp>
#include <cppuhelper/implbase2.hxx>
+#include <sax/fastattribs.hxx>
namespace oox { class TokenMap; }
@@ -36,7 +37,8 @@ typedef ::cppu::WeakImplHelper2< ::com::sun::star::lang::XServiceInfo, ::com::su
/** Wrapper implementing the com.sun.star.xml.sax.XFastTokenHandler API interface
that provides access to the tokens generated from the internal token name list.
*/
-class FastTokenHandler : public FastTokenHandler_BASE
+class FastTokenHandler : public FastTokenHandler_BASE,
+ public sax_fastparser::FastTokenHandlerBase
{
public:
explicit FastTokenHandler();
@@ -53,6 +55,9 @@ public:
virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getUTF8Identifier( sal_Int32 nToken ) throw (::com::sun::star::uno::RuntimeException);
virtual sal_Int32 SAL_CALL getTokenFromUTF8( const ::com::sun::star::uno::Sequence< sal_Int8 >& Identifier ) throw (::com::sun::star::uno::RuntimeException);
+ // Much faster direct C++ shortcut to the method that matters
+ virtual sal_Int32 getTokenDirect( const char *pToken, sal_Int32 nLength ) const;
+
private:
const TokenMap& mrTokenMap; ///< Reference to global token map singleton.
};
diff --git a/include/oox/token/tokenmap.hxx b/include/oox/token/tokenmap.hxx
index 495fa2d6eb3e..bddc0ce6a34d 100644
--- a/include/oox/token/tokenmap.hxx
+++ b/include/oox/token/tokenmap.hxx
@@ -47,9 +47,29 @@ public:
/** Returns the token identifier for the passed UTF8 token name. */
sal_Int32 getTokenFromUtf8(
- const ::com::sun::star::uno::Sequence< sal_Int8 >& rUtf8Name ) const;
+ const ::com::sun::star::uno::Sequence< sal_Int8 >& rUtf8Name ) const
+ {
+ return getTokenFromUTF8( reinterpret_cast< const char * >(
+ rUtf8Name.getConstArray() ),
+ rUtf8Name.getLength() );
+ }
+
+ /** Returns the token identifier for a UTF8 string passed in pToken */
+ sal_Int32 getTokenFromUTF8( const char *pToken, sal_Int32 nLength ) const
+ {
+ // 50% of OOXML tokens are primarily 1 lower-case character, a-z
+ if( nLength == 1)
+ {
+ sal_Char c = pToken[0];
+ if (c >= 'a' && c <= 'z')
+ return mnAlphaTokens[ c - 'a' ];
+ }
+ return getTokenPerfectHash( pToken, nLength );
+ }
private:
+ sal_Int32 getTokenPerfectHash( const char *pToken, sal_Int32 nLength ) const;
+
struct TokenName
{
OUString maUniName;