[Libreoffice-commits] core.git: xmloff/inc xmloff/source
Noel Grandin (via logerrit)
logerrit at kemper.freedesktop.org
Mon Nov 30 06:26:39 UTC 2020
xmloff/inc/XMLEmbeddedObjectImportContext.hxx | 5
xmloff/source/core/XMLEmbeddedObjectImportContext.cxx | 31 ++--
xmloff/source/draw/ximpshap.cxx | 31 ++--
xmloff/source/draw/ximpshap.hxx | 3
xmloff/source/text/XMLTextFrameContext.cxx | 119 ++++++++----------
5 files changed, 90 insertions(+), 99 deletions(-)
New commits:
commit fca175a7509b598560a612bc58b4817690665688
Author: Noel Grandin <noelgrandin at gmail.com>
AuthorDate: Sun Nov 29 20:16:53 2020 +0200
Commit: Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Mon Nov 30 07:25:58 2020 +0100
fastparser in XMLEmbeddedObjectImportContext
Change-Id: I3ba7d21bd85c494b73b3b90e73386e958e479f72
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/106842
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
diff --git a/xmloff/inc/XMLEmbeddedObjectImportContext.hxx b/xmloff/inc/XMLEmbeddedObjectImportContext.hxx
index 95942f2331c5..1f5bbdd0787c 100644
--- a/xmloff/inc/XMLEmbeddedObjectImportContext.hxx
+++ b/xmloff/inc/XMLEmbeddedObjectImportContext.hxx
@@ -38,9 +38,8 @@ public:
const OUString& GetFilterServiceName() const { return sFilterService; }
const OUString& GetFilterCLSID() const { return sCLSID; }
- XMLEmbeddedObjectImportContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
- const OUString& rLName,
- const css::uno::Reference< css::xml::sax::XAttributeList >& xAttrList );
+ XMLEmbeddedObjectImportContext( SvXMLImport& rImport, sal_Int32 nElement,
+ const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList );
virtual ~XMLEmbeddedObjectImportContext() override;
diff --git a/xmloff/source/core/XMLEmbeddedObjectImportContext.cxx b/xmloff/source/core/XMLEmbeddedObjectImportContext.cxx
index a8cc84392627..cc8115700403 100644
--- a/xmloff/source/core/XMLEmbeddedObjectImportContext.cxx
+++ b/xmloff/source/core/XMLEmbeddedObjectImportContext.cxx
@@ -25,6 +25,7 @@
#include <com/sun/star/document/XImporter.hpp>
#include <com/sun/star/uno/XComponentContext.hpp>
#include <com/sun/star/util/XModifiable2.hpp>
+#include <sal/log.hxx>
#include <tools/globname.hxx>
#include <comphelper/classids.hxx>
#include <xmloff/namespacemap.hxx>
@@ -82,7 +83,7 @@ css::uno::Reference< css::xml::sax::XFastContextHandler > XMLEmbeddedObjectImpor
sal_Int32 ,
const css::uno::Reference< css::xml::sax::XFastAttributeList >& )
{
- // we carry no state, so just re-use the same instance
+ // we have no state, so avoid allocation cost, and just use a single instance
return this;
}
@@ -139,34 +140,30 @@ void XMLEmbeddedObjectImportContext::SetComponent( Reference< XComponent > const
}
XMLEmbeddedObjectImportContext::XMLEmbeddedObjectImportContext(
- SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName,
- const Reference< XAttributeList >& xAttrList ) :
- SvXMLImportContext( rImport, nPrfx, rLName )
+ SvXMLImport& rImport, sal_Int32 nElement,
+ const Reference< XFastAttributeList >& xAttrList ) :
+ SvXMLImportContext( rImport )
{
SvGlobalName aName;
- if( nPrfx == XML_NAMESPACE_MATH &&
- IsXMLToken( rLName, XML_MATH ) )
+ if( nElement == XML_ELEMENT(MATH, XML_MATH) )
{
sFilterService = XML_IMPORT_FILTER_MATH;
aName = SvGlobalName(SO3_SM_CLASSID);
}
- else if( nPrfx == XML_NAMESPACE_OFFICE &&
- IsXMLToken( rLName, XML_DOCUMENT ) )
+ else if( nElement == XML_ELEMENT(OFFICE, XML_DOCUMENT) )
{
OUString sMime;
- sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
- for( sal_Int16 i=0; i < nAttrCount; i++ )
+ for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) )
{
- const OUString& rAttrName = xAttrList->getNameByIndex( i );
- OUString aLocalName;
- sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName );
- if( nPrefix == XML_NAMESPACE_OFFICE &&
- IsXMLToken( aLocalName, XML_MIMETYPE ) )
+ switch (aIter.getToken())
{
- sMime = xAttrList->getValueByIndex( i );
- break;
+ case XML_ELEMENT(OFFICE, XML_MIMETYPE):
+ sMime = aIter.toString();
+ break;
+ default:
+ XMLOFF_WARN_UNKNOWN("xmloff", aIter);
}
}
diff --git a/xmloff/source/draw/ximpshap.cxx b/xmloff/source/draw/ximpshap.cxx
index 65a7e2fb0eef..e9ff3b51b5cd 100644
--- a/xmloff/source/draw/ximpshap.cxx
+++ b/xmloff/source/draw/ximpshap.cxx
@@ -2739,26 +2739,21 @@ void SdXMLObjectShapeContext::processAttribute( sal_uInt16 nPrefix, const OUStri
SdXMLShapeContext::processAttribute( nPrefix, rLocalName, rValue );
}
-SvXMLImportContextRef SdXMLObjectShapeContext::CreateChildContext(
- sal_uInt16 nPrefix, const OUString& rLocalName,
- const uno::Reference<xml::sax::XAttributeList>& xAttrList )
+css::uno::Reference< css::xml::sax::XFastContextHandler > SdXMLObjectShapeContext::createFastChildContext(
+ sal_Int32 nElement,
+ const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
{
- SvXMLImportContextRef xContext;
-
- if((XML_NAMESPACE_OFFICE == nPrefix) && IsXMLToken(rLocalName, XML_BINARY_DATA))
+ if(nElement == XML_ELEMENT(OFFICE, XML_BINARY_DATA))
{
mxBase64Stream = GetImport().GetStreamForEmbeddedObjectURLFromBase64();
if( mxBase64Stream.is() )
- xContext = new XMLBase64ImportContext( GetImport(), nPrefix,
- rLocalName, xAttrList,
- mxBase64Stream );
+ return new XMLBase64ImportContext( GetImport(), mxBase64Stream );
}
- else if( ((XML_NAMESPACE_OFFICE == nPrefix) && IsXMLToken(rLocalName, XML_DOCUMENT)) ||
- ((XML_NAMESPACE_MATH == nPrefix) && IsXMLToken(rLocalName, XML_MATH)) )
+ else if( nElement == XML_ELEMENT(OFFICE, XML_DOCUMENT) ||
+ nElement == XML_ELEMENT(MATH, XML_MATH) )
{
rtl::Reference<XMLEmbeddedObjectImportContext> xEContext(
- new XMLEmbeddedObjectImportContext(GetImport(), nPrefix,
- rLocalName, xAttrList));
+ new XMLEmbeddedObjectImportContext(GetImport(), nElement, xAttrList));
maCLSID = xEContext->GetFilterCLSID();
if( !maCLSID.isEmpty() )
{
@@ -2773,8 +2768,16 @@ SvXMLImportContextRef SdXMLObjectShapeContext::CreateChildContext(
xEContext->SetComponent(xComp);
}
}
- xContext = xEContext.get();
+ return xEContext.get();
}
+ return nullptr;
+}
+
+SvXMLImportContextRef SdXMLObjectShapeContext::CreateChildContext(
+ sal_uInt16 nPrefix, const OUString& rLocalName,
+ const uno::Reference<xml::sax::XAttributeList>& xAttrList )
+{
+ SvXMLImportContextRef xContext;
// delegate to parent class if no context could be created
if (!xContext)
diff --git a/xmloff/source/draw/ximpshap.hxx b/xmloff/source/draw/ximpshap.hxx
index 8a29b037229a..84a76b315d55 100644
--- a/xmloff/source/draw/ximpshap.hxx
+++ b/xmloff/source/draw/ximpshap.hxx
@@ -421,6 +421,9 @@ public:
virtual void StartElement( const css::uno::Reference< css::xml::sax::XAttributeList >& xAttrList ) override;
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override;
+ virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
+ sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override;
+
virtual SvXMLImportContextRef CreateChildContext( sal_uInt16 nPrefix, const OUString& rLocalName,
const css::uno::Reference< css::xml::sax::XAttributeList>& xAttrList ) override;
diff --git a/xmloff/source/text/XMLTextFrameContext.cxx b/xmloff/source/text/XMLTextFrameContext.cxx
index 08ad2d7dc489..0cf2d1832736 100644
--- a/xmloff/source/text/XMLTextFrameContext.cxx
+++ b/xmloff/source/text/XMLTextFrameContext.cxx
@@ -154,44 +154,36 @@ namespace {
class XMLTextFrameParam_Impl : public SvXMLImportContext
{
public:
-
-
- XMLTextFrameParam_Impl( SvXMLImport& rImport, sal_uInt16 nPrfx,
- const OUString& rLName,
- const css::uno::Reference< css::xml::sax::XAttributeList > & xAttrList,
+ XMLTextFrameParam_Impl( SvXMLImport& rImport,
+ const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList,
ParamMap &rParamMap);
};
}
XMLTextFrameParam_Impl::XMLTextFrameParam_Impl(
- SvXMLImport& rImport, sal_uInt16 nPrfx,
- const OUString& rLName,
- const css::uno::Reference< css::xml::sax::XAttributeList > & xAttrList,
+ SvXMLImport& rImport,
+ const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList,
ParamMap &rParamMap):
- SvXMLImportContext( rImport, nPrfx, rLName )
+ SvXMLImportContext( rImport )
{
OUString sName, sValue;
bool bFoundValue = false; // to allow empty values
- sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
- for( sal_Int16 i=0; i < nAttrCount; i++ )
+ for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
{
- const OUString& rAttrName = xAttrList->getNameByIndex( i );
- const OUString& rValue = xAttrList->getValueByIndex( i );
-
- OUString aLocalName;
- sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName );
- if ( XML_NAMESPACE_DRAW == nPrefix )
+ switch (aIter.getToken())
{
- if( IsXMLToken(aLocalName, XML_VALUE) )
- {
- sValue = rValue;
- bFoundValue=true;
- }
- else if( IsXMLToken(aLocalName, XML_NAME) )
+ case XML_ELEMENT(DRAW, XML_VALUE):
{
- sName = rValue;
+ sValue = aIter.toString();
+ bFoundValue = true;
+ break;
}
+ case XML_ELEMENT(DRAW, XML_NAME):
+ sName = aIter.toString();
+ break;
+ default:
+ XMLOFF_WARN_UNKNOWN("xmloff", aIter);
}
}
if (!sName.isEmpty() && bFoundValue )
@@ -409,6 +401,9 @@ public:
virtual void SAL_CALL characters( const OUString& rChars ) override;
+ virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
+ sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override;
+
SvXMLImportContextRef CreateChildContext( sal_uInt16 nPrefix,
const OUString& rLocalName,
const css::uno::Reference< css::xml::sax::XAttributeList > & xAttrList ) override;
@@ -1169,60 +1164,44 @@ void XMLTextFrameContext_Impl::endFastElement(sal_Int32 )
GetImport().GetTextImport()->endAppletOrPlugin( xPropSet, aParamMap);
}
-SvXMLImportContextRef XMLTextFrameContext_Impl::CreateChildContext(
- sal_uInt16 nPrefix,
- const OUString& rLocalName,
- const Reference< XAttributeList > & xAttrList )
+css::uno::Reference< css::xml::sax::XFastContextHandler > XMLTextFrameContext_Impl::createFastChildContext(
+ sal_Int32 nElement,
+ const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
{
- SvXMLImportContext *pContext = nullptr;
-
- if( XML_NAMESPACE_DRAW == nPrefix )
+ if( nElement == XML_ELEMENT(DRAW, XML_PARAM) )
{
- if ( (nType == XML_TEXT_FRAME_APPLET || nType == XML_TEXT_FRAME_PLUGIN) &&
- IsXMLToken( rLocalName, XML_PARAM ) )
- {
- pContext = new XMLTextFrameParam_Impl( GetImport(),
- nPrefix, rLocalName,
+ if ( nType == XML_TEXT_FRAME_APPLET || nType == XML_TEXT_FRAME_PLUGIN )
+ return new XMLTextFrameParam_Impl( GetImport(),
xAttrList, aParamMap );
- }
}
- else if( XML_NAMESPACE_OFFICE == nPrefix )
+ else if( nElement == XML_ELEMENT(OFFICE, XML_BINARY_DATA) )
{
- if( IsXMLToken( rLocalName, XML_BINARY_DATA ) )
+ if( !xPropSet.is() && !xBase64Stream.is() && !bCreateFailed )
{
- if( !xPropSet.is() && !xBase64Stream.is() && !bCreateFailed )
+ switch( nType )
{
- switch( nType )
- {
- case XML_TEXT_FRAME_GRAPHIC:
- xBase64Stream =
- GetImport().GetStreamForGraphicObjectURLFromBase64();
- break;
- case XML_TEXT_FRAME_OBJECT_OLE:
- xBase64Stream =
- GetImport().GetStreamForEmbeddedObjectURLFromBase64();
- break;
- }
- if( xBase64Stream.is() )
- pContext = new XMLBase64ImportContext( GetImport(), nPrefix,
- rLocalName, xAttrList,
- xBase64Stream );
+ case XML_TEXT_FRAME_GRAPHIC:
+ xBase64Stream =
+ GetImport().GetStreamForGraphicObjectURLFromBase64();
+ break;
+ case XML_TEXT_FRAME_OBJECT_OLE:
+ xBase64Stream =
+ GetImport().GetStreamForEmbeddedObjectURLFromBase64();
+ break;
}
+ if( xBase64Stream.is() )
+ return new XMLBase64ImportContext( GetImport(), xBase64Stream );
}
}
// Correction of condition which also avoids warnings. (#i100480#)
- if( !pContext &&
- ( XML_TEXT_FRAME_OBJECT == nType &&
- ( ( XML_NAMESPACE_OFFICE == nPrefix &&
- IsXMLToken( rLocalName, XML_DOCUMENT ) ) ||
- ( XML_NAMESPACE_MATH == nPrefix &&
- IsXMLToken( rLocalName, XML_MATH ) ) ) ) )
+ if( XML_TEXT_FRAME_OBJECT == nType &&
+ ( nElement == XML_ELEMENT(OFFICE, XML_DOCUMENT) ||
+ nElement == XML_ELEMENT(MATH, XML_MATH) ) )
{
if( !xPropSet.is() && !bCreateFailed )
{
XMLEmbeddedObjectImportContext *pEContext =
- new XMLEmbeddedObjectImportContext( GetImport(), nPrefix,
- rLocalName, xAttrList );
+ new XMLEmbeddedObjectImportContext( GetImport(), nElement, xAttrList );
sFilterService = pEContext->GetFilterServiceName();
if( !sFilterService.isEmpty() )
{
@@ -1237,10 +1216,20 @@ SvXMLImportContextRef XMLTextFrameContext_Impl::CreateChildContext(
pEContext->SetComponent( aXComponent );
}
}
- pContext = pEContext;
+ return pEContext;
}
}
- if( !pContext && xOldTextCursor.is() ) // text-box
+ return nullptr;
+}
+
+SvXMLImportContextRef XMLTextFrameContext_Impl::CreateChildContext(
+ sal_uInt16 nPrefix,
+ const OUString& rLocalName,
+ const Reference< XAttributeList > & xAttrList )
+{
+ SvXMLImportContext *pContext = nullptr;
+
+ if( xOldTextCursor.is() ) // text-box
pContext = GetImport().GetTextImport()->CreateTextChildContext(
GetImport(), nPrefix, rLocalName, xAttrList,
XMLTextType::TextBox );
More information about the Libreoffice-commits
mailing list