diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-08-29 11:19:28 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-12-07 08:52:49 +0100 |
commit | 5080bb930de3ecfce8ab78bbd23a9d48c2f2bfa0 (patch) | |
tree | 9f92d184627177dbd83dedda40d4a4abb531381e /xmloff/source/core | |
parent | 121464be43830a6f6bfbc27a17c8e0bc7577f455 (diff) |
convert SvXMLImport to fastparser, drop slowparser paths
Change-Id: I0f880a7680373043fecf083cdf4de8b0bb7041a2
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/103775
Tested-by: Noel Grandin <noel.grandin@collabora.co.uk>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'xmloff/source/core')
-rw-r--r-- | xmloff/source/core/XMLBase64ImportContext.cxx | 9 | ||||
-rw-r--r-- | xmloff/source/core/xmlictxt.cxx | 94 | ||||
-rw-r--r-- | xmloff/source/core/xmlimp.cxx | 103 |
3 files changed, 1 insertions, 205 deletions
diff --git a/xmloff/source/core/XMLBase64ImportContext.cxx b/xmloff/source/core/XMLBase64ImportContext.cxx index 504460bff96a..301865a26c10 100644 --- a/xmloff/source/core/XMLBase64ImportContext.cxx +++ b/xmloff/source/core/XMLBase64ImportContext.cxx @@ -30,15 +30,6 @@ using namespace ::com::sun::star::io; XMLBase64ImportContext::XMLBase64ImportContext( - SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName, - const Reference< XAttributeList >&, - const Reference< XOutputStream >& rOut ) : - SvXMLImportContext( rImport, nPrfx, rLName ), - xOut( rOut ) -{ -} - -XMLBase64ImportContext::XMLBase64ImportContext( SvXMLImport& rImport, const Reference< XOutputStream >& rOut ) : SvXMLImportContext( rImport ), diff --git a/xmloff/source/core/xmlictxt.cxx b/xmloff/source/core/xmlictxt.cxx index b41d847805f0..360763349c93 100644 --- a/xmloff/source/core/xmlictxt.cxx +++ b/xmloff/source/core/xmlictxt.cxx @@ -27,21 +27,9 @@ using namespace ::com::sun::star; -SvXMLImportContext::SvXMLImportContext( SvXMLImport& rImp, sal_uInt16 nPrfx, - const OUString& rLName ) - : mrImport(rImp) - , maLocalName(rLName) - , m_nRefCount(0) - , mnPrefix(nPrfx) - , mbPrefixAndLocalNameFilledIn(true) -{ -} - SvXMLImportContext::SvXMLImportContext( SvXMLImport& rImp ) : mrImport(rImp) , m_nRefCount(0) - , mnPrefix(0) - , mbPrefixAndLocalNameFilledIn(false) { } @@ -49,50 +37,13 @@ SvXMLImportContext::~SvXMLImportContext() { } -SvXMLImportContextRef SvXMLImportContext::CreateChildContext( sal_uInt16 /*nPrefix*/, - const OUString& /*rLocalName*/, - const uno::Reference<xml::sax::XAttributeList>& ) -{ - return nullptr; -} - -void SvXMLImportContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& ) -{ -} - void SvXMLImportContext::endFastElement(sal_Int32 ) { } // css::xml::sax::XFastContextHandler: -void SAL_CALL SvXMLImportContext::startFastElement(sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList > & Attribs) +void SAL_CALL SvXMLImportContext::startFastElement(sal_Int32 /*nElement*/, const uno::Reference< xml::sax::XFastAttributeList > & ) { - const OUString& rPrefix = SvXMLImport::getNamespacePrefixFromToken(nElement, &GetImport().GetNamespaceMap()); - const OUString& rLocalName = SvXMLImport::getNameFromToken( nElement ); - startUnknownElement( SvXMLImport::aDefaultNamespace, (rPrefix.isEmpty())? rLocalName : rPrefix + SvXMLImport::aNamespaceSeparator + rLocalName, Attribs ); - mrImport.maAttrList->Clear(); - mrImport.maNamespaceHandler->addNSDeclAttributes( mrImport.maAttrList ); - - for( auto &it : sax_fastparser::castToFastAttributeList( Attribs ) ) - { - sal_Int32 nToken = it.getToken(); - const OUString& rAttrNamespacePrefix = SvXMLImport::getNamespacePrefixFromToken(nToken, &GetImport().GetNamespaceMap()); - OUString sAttrName = SvXMLImport::getNameFromToken( nToken ); - if ( !rAttrNamespacePrefix.isEmpty() ) - sAttrName = rAttrNamespacePrefix + SvXMLImport::aNamespaceSeparator + sAttrName; - - mrImport.maAttrList->AddAttribute( sAttrName, "CDATA", it.toString() ); - } - - const uno::Sequence< xml::Attribute > unknownAttribs = Attribs->getUnknownAttributes(); - for ( const auto& rUnknownAttrib : unknownAttribs ) - { - const OUString& rAttrValue = rUnknownAttrib.Value; - const OUString& rAttrName = rUnknownAttrib.Name; - // note: rAttrName is expected to be namespace-prefixed here - mrImport.maAttrList->AddAttribute( rAttrName, "CDATA", rAttrValue ); - } - StartElement( mrImport.maAttrList.get() ); } void SAL_CALL SvXMLImportContext::startUnknownElement(const OUString & /*rNamespace*/, const OUString & /*rElementName*/, @@ -110,49 +61,6 @@ uno::Reference< xml::sax::XFastContextHandler > SAL_CALL SvXMLImportContext::cre return nullptr; } -css::uno::Reference< css::xml::sax::XFastContextHandler > SvXMLImportContext::createFastChildContextFallback(sal_Int32 Element, const uno::Reference< xml::sax::XFastAttributeList > & Attribs) -{ - auto p = createFastChildContext(Element, Attribs); - if (p) - return p; - - // fall back to slow-parser path - const OUString& rPrefix = SvXMLImport::getNamespacePrefixFromToken(Element, &mrImport.GetNamespaceMap()); - const OUString& rLocalName = SvXMLImport::getNameFromToken( Element ); - OUString aName = rPrefix.isEmpty() ? rLocalName : rPrefix + SvXMLImport::aNamespaceSeparator + rLocalName; - OUString aLocalName; - sal_uInt16 nPrefix = - mrImport.mpNamespaceMap->GetKeyByAttrName( aName, &aLocalName ); - - mrImport.maAttrList->Clear(); - - if ( Attribs.is() ) - { - for( auto &it : sax_fastparser::castToFastAttributeList( Attribs ) ) - { - sal_Int32 nToken = it.getToken(); - const OUString& rAttrNamespacePrefix = SvXMLImport::getNamespacePrefixFromToken(nToken, &mrImport.GetNamespaceMap()); - OUString sAttrName = SvXMLImport::getNameFromToken( nToken ); - if ( !rAttrNamespacePrefix.isEmpty() ) - sAttrName = rAttrNamespacePrefix + SvXMLImport::aNamespaceSeparator + sAttrName; - - mrImport.maAttrList->AddAttribute( sAttrName, "CDATA", it.toString() ); - } - - const uno::Sequence< xml::Attribute > unknownAttribs = Attribs->getUnknownAttributes(); - for ( const auto& rUnknownAttrib : unknownAttribs ) - { - const OUString& rAttrValue = rUnknownAttrib.Value; - const OUString& rAttrName = rUnknownAttrib.Name; - // note: rAttrName is expected to be namespace-prefixed here - mrImport.maAttrList->AddAttribute( rAttrName, "CDATA", rAttrValue ); - } - } - - SAL_INFO("xmloff.core", "calling CreateChildContext on " << typeid(*this).name()); - return CreateChildContext(nPrefix, aLocalName, mrImport.maAttrList.get() ).get(); -} - uno::Reference< xml::sax::XFastContextHandler > SAL_CALL SvXMLImportContext::createUnknownChildContext (const OUString & /*rNamespace*/, const OUString & /*rName*/, const uno::Reference< xml::sax::XFastAttributeList > & /*Attribs*/) { diff --git a/xmloff/source/core/xmlimp.cxx b/xmloff/source/core/xmlimp.cxx index 03e076c0cba3..d2c346fbe5f6 100644 --- a/xmloff/source/core/xmlimp.cxx +++ b/xmloff/source/core/xmlimp.cxx @@ -779,44 +779,6 @@ void SAL_CALL SvXMLImport::startFastElement (sal_Int32 Element, const SvXMLImportContextRef & pHandler = maContexts.top(); SAL_INFO("xmloff.core", "calling createFastChildContext on " << typeid(*pHandler.get()).name()); auto tmp = pHandler->createFastChildContext( Element, Attribs ); - if (!tmp) - { - // fall back to slow-parser path - const OUString& rPrefix = SvXMLImport::getNamespacePrefixFromToken(Element, &GetNamespaceMap()); - const OUString& rLocalName = SvXMLImport::getNameFromToken( Element ); - OUString aName = rPrefix.isEmpty() ? rLocalName : rPrefix + SvXMLImport::aNamespaceSeparator + rLocalName; - OUString aLocalName; - sal_uInt16 nPrefix = - mpNamespaceMap->GetKeyByAttrName( aName, &aLocalName ); - - maAttrList->Clear(); - - if ( Attribs.is() ) - { - for( auto &it : sax_fastparser::castToFastAttributeList( Attribs ) ) - { - sal_Int32 nToken = it.getToken(); - const OUString& rAttrNamespacePrefix = SvXMLImport::getNamespacePrefixFromToken(nToken, &GetNamespaceMap()); - OUString sAttrName = SvXMLImport::getNameFromToken( nToken ); - if ( !rAttrNamespacePrefix.isEmpty() ) - sAttrName = rAttrNamespacePrefix + SvXMLImport::aNamespaceSeparator + sAttrName; - - maAttrList->AddAttribute( sAttrName, "CDATA", it.toString() ); - } - - const uno::Sequence< xml::Attribute > unknownAttribs = Attribs->getUnknownAttributes(); - for ( const auto& rUnknownAttrib : unknownAttribs ) - { - const OUString& rAttrValue = rUnknownAttrib.Value; - const OUString& rAttrName = rUnknownAttrib.Name; - // note: rAttrName is expected to be namespace-prefixed here - maAttrList->AddAttribute( rAttrName, "CDATA", rAttrValue ); - } - } - - SAL_INFO("xmloff.core", "calling CreateChildContext on " << typeid(*pHandler).name()); - tmp = pHandler->CreateChildContext(nPrefix, aLocalName, maAttrList.get() ).get(); - } xContext = dynamic_cast<SvXMLImportContext*>(tmp.get()); assert((tmp && xContext) || (!tmp && !xContext)); } @@ -851,41 +813,6 @@ void SAL_CALL SvXMLImport::startUnknownElement (const OUString & rNamespace, con const SvXMLImportContextRef & pHandler = maContexts.top(); SAL_INFO("xmloff.core", "calling createUnknownChildContext on " << typeid(*pHandler.get()).name()); auto tmp = pHandler->createUnknownChildContext( rNamespace, rName, Attribs ); - if (!tmp) - { - // fall back to slow-parser path - OUString aLocalName; - sal_uInt16 nPrefix = mpNamespaceMap->GetKeyByAttrName( rName, &aLocalName ); - - maAttrList->Clear(); - maNamespaceHandler->addNSDeclAttributes( maAttrList ); - - if ( Attribs.is() ) - { - for( auto &it : sax_fastparser::castToFastAttributeList( Attribs ) ) - { - sal_Int32 nToken = it.getToken(); - const OUString& rAttrNamespacePrefix = SvXMLImport::getNamespacePrefixFromToken(nToken, &GetNamespaceMap()); - OUString sAttrName = SvXMLImport::getNameFromToken( nToken ); - if ( !rAttrNamespacePrefix.isEmpty() ) - sAttrName = rAttrNamespacePrefix + SvXMLImport::aNamespaceSeparator + sAttrName; - - maAttrList->AddAttribute( sAttrName, "CDATA", it.toString() ); - } - - const uno::Sequence< xml::Attribute > unknownAttribs = Attribs->getUnknownAttributes(); - for ( const auto& rUnknownAttrib : unknownAttribs ) - { - const OUString& rAttrValue = rUnknownAttrib.Value; - const OUString& rAttrName = rUnknownAttrib.Name; - // note: rAttrName is expected to be namespace-prefixed here - maAttrList->AddAttribute( rAttrName, "CDATA", rAttrValue ); - } - } - - SAL_INFO("xmloff.core", "calling CreateChildContext on " << typeid(*pHandler).name()); - tmp = pHandler->CreateChildContext(nPrefix, aLocalName, maAttrList.get() ).get(); - } xContext = dynamic_cast<SvXMLImportContext*>(tmp.get()); assert((tmp && xContext) || (!tmp && !xContext)); } @@ -1582,36 +1509,6 @@ XMLEventImportHelper& SvXMLImport::GetEventImport() return *mpEventImportHelper; } -css::uno::Reference< css::xml::sax::XAttributeList > SvXMLImport::convertToSlowAttrList(const uno::Reference< xml::sax::XFastAttributeList > & Attribs) -{ - maAttrList->Clear(); - - if ( Attribs.is() ) - { - for( auto &it : sax_fastparser::castToFastAttributeList( Attribs ) ) - { - sal_Int32 nToken = it.getToken(); - const OUString& rAttrNamespacePrefix = SvXMLImport::getNamespacePrefixFromToken(nToken, &GetNamespaceMap()); - OUString sAttrName = SvXMLImport::getNameFromToken( nToken ); - if ( !rAttrNamespacePrefix.isEmpty() ) - sAttrName = rAttrNamespacePrefix + SvXMLImport::aNamespaceSeparator + sAttrName; - - maAttrList->AddAttribute( sAttrName, "CDATA", it.toString() ); - } - - const uno::Sequence< xml::Attribute > unknownAttribs = Attribs->getUnknownAttributes(); - for ( const auto& rUnknownAttrib : unknownAttribs ) - { - const OUString& rAttrValue = rUnknownAttrib.Value; - const OUString& rAttrName = rUnknownAttrib.Name; - // note: rAttrName is expected to be namespace-prefixed here - maAttrList->AddAttribute( rAttrName, "CDATA", rAttrValue ); - } - } - - return maAttrList.get(); -} - void SvXMLImport::SetFontDecls( XMLFontStylesContext *pFontDecls ) { if (mxFontDecls.is()) |