From 2df047bfd1f618329872261ca0600fe232ad8cfe Mon Sep 17 00:00:00 2001 From: Michael Meeks Date: Fri, 11 Oct 2013 21:46:45 +0100 Subject: fastparser: cache default namespace token for ooxml. Change-Id: Iee98ec92380d6d0404ab236e062ddbc2378cda43 --- sax/source/fastparser/fastparser.cxx | 30 ++++++++++++++++++------------ sax/source/fastparser/fastparser.hxx | 14 +++++++++++--- 2 files changed, 29 insertions(+), 15 deletions(-) (limited to 'sax') diff --git a/sax/source/fastparser/fastparser.cxx b/sax/source/fastparser/fastparser.cxx index 9a31cc852005..825160f998a0 100644 --- a/sax/source/fastparser/fastparser.cxx +++ b/sax/source/fastparser/fastparser.cxx @@ -420,10 +420,8 @@ OUString FastSaxParser::GetNamespaceURL( const sal_Char*pPrefix, int nPrefixLen // -------------------------------------------------------------------- -sal_Int32 FastSaxParser::GetTokenWithNamespaceURL( const OUString& rNamespaceURL, const sal_Char* pName, int nNameLen ) +sal_Int32 FastSaxParser::GetTokenWithContextNamespace( sal_Int32 nNamespaceToken, const sal_Char* pName, int nNameLen ) { - sal_Int32 nNamespaceToken = GetNamespaceToken( rNamespaceURL ); - if( nNamespaceToken != FastToken::DONTKNOW ) { sal_Int32 nNameToken = GetToken( pName, nNameLen ); @@ -749,9 +747,13 @@ void FastSaxParser::callbackStartElement( const XML_Char* pwName, const XML_Char sal_Int32 nNameLen, nPrefixLen; const XML_Char *pName; const XML_Char *pPrefix; - OUString aNamespace; + OUString sNamespace; + sal_Int32 nNamespaceToken = FastToken::DONTKNOW; if (!rEntity.maNamespaceStack.empty()) - aNamespace = rEntity.maNamespaceStack.top(); + { + sNamespace = rEntity.maNamespaceStack.top().msName; + nNamespaceToken = rEntity.maNamespaceStack.top().mnToken; + } try { @@ -777,8 +779,9 @@ void FastSaxParser::callbackStartElement( const XML_Char* pwName, const XML_Char { if( (nNameLen == 5) && (strcmp( pName, "xmlns" ) == 0) ) { - // namespace of the element found - aNamespace = OUString( awAttributes[i+1], strlen( awAttributes[i+1] ), RTL_TEXTENCODING_UTF8 ); + // default namespace is the attribute value + sNamespace = OUString( awAttributes[i+1], strlen( awAttributes[i+1] ), RTL_TEXTENCODING_UTF8 ); + nNamespaceToken = GetNamespaceToken( sNamespace ); } } } @@ -816,17 +819,20 @@ void FastSaxParser::callbackStartElement( const XML_Char* pwName, const XML_Char splitName( pwName, pPrefix, nPrefixLen, pName, nNameLen ); if( nPrefixLen > 0 ) nElementToken = GetTokenWithPrefix( pPrefix, nPrefixLen, pName, nNameLen ); - else if( !aNamespace.isEmpty() ) - nElementToken = GetTokenWithNamespaceURL( aNamespace, pName, nNameLen ); + else if( !sNamespace.isEmpty() ) + nElementToken = GetTokenWithContextNamespace( nNamespaceToken, pName, nNameLen ); else nElementToken = GetToken( pName ); if( nElementToken == FastToken::DONTKNOW ) if( nPrefixLen > 0 ) - aNamespace = GetNamespaceURL( pPrefix, nPrefixLen ); + { + sNamespace = GetNamespaceURL( pPrefix, nPrefixLen ); + nNamespaceToken = GetNamespaceToken( sNamespace ); + } - rEntity.maNamespaceStack.push(aNamespace); - rEntity.startElement( nElementToken, aNamespace, + rEntity.maNamespaceStack.push( NameWithToken(sNamespace, nNamespaceToken) ); + rEntity.startElement( nElementToken, sNamespace, OUString(pName, nNameLen, RTL_TEXTENCODING_UTF8), rEntity.mxAttributes.get() ); } catch (const Exception& e) diff --git a/sax/source/fastparser/fastparser.hxx b/sax/source/fastparser/fastparser.hxx index 184721251122..d604a8421f19 100644 --- a/sax/source/fastparser/fastparser.hxx +++ b/sax/source/fastparser/fastparser.hxx @@ -51,6 +51,14 @@ typedef ::boost::shared_ptr< NamespaceDefine > NamespaceDefineRef; typedef ::boost::unordered_map< OUString, sal_Int32, OUStringHash, ::std::equal_to< OUString > > NamespaceMap; +struct NameWithToken +{ + OUString msName; + sal_Int32 mnToken; + NameWithToken(const OUString& sName, const sal_Int32& nToken): + msName(sName), mnToken(nToken) {} +}; + // -------------------------------------------------------------------- struct SaxContext @@ -90,7 +98,7 @@ struct Entity : public ParserData // therefore the exception must be saved somewhere. ::com::sun::star::uno::Any maSavedException; - ::std::stack< OUString > maNamespaceStack; + ::std::stack< NameWithToken > maNamespaceStack; /* Context for main thread consuming events. * startElement() stores the data, which characters() and endElement() uses */ @@ -138,7 +146,7 @@ public: void callbackStartElement( const XML_Char* name, const XML_Char** atts ); void callbackEndElement( const XML_Char* name ); void callbackCharacters( const XML_Char* s, int nLen ); - int callbackExternalEntityRef( XML_Parser parser, const XML_Char *openEntityNames, const XML_Char *base, const XML_Char *systemId, const XML_Char *publicId); + int callbackExternalEntityRef( XML_Parser parser, const XML_Char *openEntityNames, const XML_Char *base, const XML_Char *systemId, const XML_Char *publicId); void callbackEntityDecl(const XML_Char *entityName, int is_parameter_entity, const XML_Char *value, int value_length, const XML_Char *base, const XML_Char *systemId, const XML_Char *publicId, @@ -156,7 +164,7 @@ private: OUString GetNamespaceURL( const OString& rPrefix ) throw (::com::sun::star::xml::sax::SAXException); OUString GetNamespaceURL( const sal_Char*pPrefix, int nPrefixLen ) throw (::com::sun::star::xml::sax::SAXException); sal_Int32 GetNamespaceToken( const OUString& rNamespaceURL ); - sal_Int32 GetTokenWithNamespaceURL( const OUString& rNamespaceURL, const sal_Char* pName, int nNameLen ); + sal_Int32 GetTokenWithContextNamespace( sal_Int32 nNamespaceToken, const sal_Char* pName, int nNameLen ); void DefineNamespace( const OString& rPrefix, const sal_Char* pNamespaceURL ); void pushContext(); -- cgit