summaryrefslogtreecommitdiff
path: root/sax
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2020-03-11 14:19:34 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2020-04-25 12:13:26 +0200
commit0dbc76a3ca25f43232073484541504e342380d0a (patch)
treed0324098ee97a845cbbf9f7205a43af94ca7306d /sax
parentaf9642350db024e9a9ff73f46693ff5d0a4ce66b (diff)
make FastParser always take a FastTokenHandlerBase subclass
since most of the call sites already do, and we can skip the slow path this way. Change-Id: I64ed30c51324e0510818f42ef838f97c401bb6dd Reviewed-on: https://gerrit.libreoffice.org/c/core/+/90326 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sax')
-rw-r--r--sax/CppunitTest_sax_parser.mk1
-rw-r--r--sax/qa/cppunit/parser.cxx7
-rw-r--r--sax/qa/cppunit/xmlimport.cxx3
-rw-r--r--sax/source/fastparser/fastparser.cxx17
-rw-r--r--sax/source/tools/fastattribs.cxx20
-rw-r--r--sax/source/tools/fshelper.cxx2
6 files changed, 20 insertions, 30 deletions
diff --git a/sax/CppunitTest_sax_parser.mk b/sax/CppunitTest_sax_parser.mk
index 4c1fe31015bd..59a90fd13f67 100644
--- a/sax/CppunitTest_sax_parser.mk
+++ b/sax/CppunitTest_sax_parser.mk
@@ -22,6 +22,7 @@ $(eval $(call gb_CppunitTest_use_libraries,sax_parser, \
unotest \
expwrap \
sal \
+ sax \
test \
))
diff --git a/sax/qa/cppunit/parser.cxx b/sax/qa/cppunit/parser.cxx
index 2fb3b400d000..e5fd9e2ab23c 100644
--- a/sax/qa/cppunit/parser.cxx
+++ b/sax/qa/cppunit/parser.cxx
@@ -16,6 +16,7 @@
#include <cppuhelper/implbase.hxx>
#include <sax/fastparser.hxx>
+#include <sax/fastattribs.hxx>
#include <test/bootstrapfixture.hxx>
#include <rtl/ref.hxx>
@@ -24,7 +25,7 @@ using namespace css::xml::sax;
namespace {
-class DummyTokenHandler : public cppu::WeakImplHelper< xml::sax::XFastTokenHandler >
+class DummyTokenHandler : public sax_fastparser::FastTokenHandlerBase
{
public:
DummyTokenHandler() {}
@@ -38,6 +39,10 @@ public:
CPPUNIT_ASSERT_MESSAGE( "getUTF8Identifier: unexpected call", false );
return uno::Sequence<sal_Int8>();
}
+ virtual sal_Int32 getTokenDirect( const char * /* pToken */, sal_Int32 /* nLength */ ) const override
+ {
+ return -1;
+ }
};
class ParserTest: public test::BootstrapFixture
diff --git a/sax/qa/cppunit/xmlimport.cxx b/sax/qa/cppunit/xmlimport.cxx
index 91c955982746..449c9ef3b38c 100644
--- a/sax/qa/cppunit/xmlimport.cxx
+++ b/sax/qa/cppunit/xmlimport.cxx
@@ -251,8 +251,7 @@ void SAL_CALL NSDocumentHandler::startElement( const OUString& aName, const Refe
CPPUNIT_ASSERT(false);
}
-class DummyTokenHandler : public cppu::WeakImplHelper< XFastTokenHandler >,
- public sax_fastparser::FastTokenHandlerBase
+class DummyTokenHandler : public sax_fastparser::FastTokenHandlerBase
{
public:
const static OString tokens[];
diff --git a/sax/source/fastparser/fastparser.cxx b/sax/source/fastparser/fastparser.cxx
index bca3f502defc..1c4d5531a747 100644
--- a/sax/source/fastparser/fastparser.cxx
+++ b/sax/source/fastparser/fastparser.cxx
@@ -121,8 +121,7 @@ struct SaxContext
struct ParserData
{
css::uno::Reference< css::xml::sax::XFastDocumentHandler > mxDocumentHandler;
- css::uno::Reference< css::xml::sax::XFastTokenHandler > mxTokenHandler;
- FastTokenHandlerBase* mpTokenHandler;
+ rtl::Reference<FastTokenHandlerBase> mxTokenHandler;
css::uno::Reference< css::xml::sax::XErrorHandler > mxErrorHandler;
css::uno::Reference< css::xml::sax::XFastNamespaceHandler >mxNamespaceHandler;
@@ -370,7 +369,6 @@ OUString SAL_CALL FastLocatorImpl::getSystemId()
}
ParserData::ParserData()
- : mpTokenHandler( nullptr )
{}
Entity::Entity(const ParserData& rData)
@@ -662,8 +660,7 @@ void FastSaxParserImpl::DefineNamespace( const OString& rPrefix, const OUString&
sal_Int32 FastSaxParserImpl::GetToken( const xmlChar* pName, sal_Int32 nameLen /* = 0 */ )
{
- return FastTokenHandlerBase::getTokenFromChars( getEntity().mxTokenHandler,
- getEntity().mpTokenHandler,
+ return FastTokenHandlerBase::getTokenFromChars( getEntity(). mxTokenHandler.get(),
XML_CAST( pName ), nameLen ); // uses utf-8
}
@@ -883,8 +880,8 @@ void FastSaxParserImpl::setFastDocumentHandler( const Reference< XFastDocumentHa
void FastSaxParserImpl::setTokenHandler( const Reference< XFastTokenHandler >& xHandler )
{
- maData.mxTokenHandler = xHandler;
- maData.mpTokenHandler = dynamic_cast< FastTokenHandlerBase *>( xHandler.get() );
+ assert( dynamic_cast< FastTokenHandlerBase *>( xHandler.get() ) && "we expect this handler to be a subclass of FastTokenHandlerBase" );
+ maData.mxTokenHandler = dynamic_cast< FastTokenHandlerBase *>( xHandler.get() );
}
void FastSaxParserImpl::registerNamespace( const OUString& NamespaceURL, sal_Int32 NamespaceToken )
@@ -1118,8 +1115,7 @@ void FastSaxParserImpl::callbackStartElement(const xmlChar *localName , const xm
}
else
rEvent.mxAttributes.set(
- new FastAttributeList( rEntity.mxTokenHandler,
- rEntity.mpTokenHandler ) );
+ new FastAttributeList( rEntity.mxTokenHandler.get() ) );
if( rEntity.mxNamespaceHandler.is() )
{
@@ -1130,8 +1126,7 @@ void FastSaxParserImpl::callbackStartElement(const xmlChar *localName , const xm
}
else
rEvent.mxDeclAttributes.set(
- new FastAttributeList( rEntity.mxTokenHandler,
- rEntity.mpTokenHandler ) );
+ new FastAttributeList( rEntity.mxTokenHandler.get() ) );
}
OUString sNamespace;
diff --git a/sax/source/tools/fastattribs.cxx b/sax/source/tools/fastattribs.cxx
index 587749938c6b..3df391c86150 100644
--- a/sax/source/tools/fastattribs.cxx
+++ b/sax/source/tools/fastattribs.cxx
@@ -54,10 +54,8 @@ void UnknownAttribute::FillAttribute( Attribute* pAttrib ) const
}
}
-FastAttributeList::FastAttributeList( const css::uno::Reference< css::xml::sax::XFastTokenHandler >& xTokenHandler,
- sax_fastparser::FastTokenHandlerBase *pTokenHandler)
-: mxTokenHandler( xTokenHandler ),
- mpTokenHandler( pTokenHandler )
+FastAttributeList::FastAttributeList( sax_fastparser::FastTokenHandlerBase *pTokenHandler)
+: mpTokenHandler( pTokenHandler )
{
// random initial size of buffer to store attribute values
mnChunkLength = 58;
@@ -140,7 +138,7 @@ sal_Int32 FastAttributeList::getValueToken( ::sal_Int32 Token )
for (size_t i = 0; i < maAttributeTokens.size(); ++i)
if (maAttributeTokens[i] == Token)
return FastTokenHandlerBase::getTokenFromChars(
- mxTokenHandler, mpTokenHandler,
+ mpTokenHandler,
getFastAttributeValue(i),
AttributeValueLength( i ) );
@@ -152,7 +150,7 @@ sal_Int32 FastAttributeList::getOptionalValueToken( ::sal_Int32 Token, ::sal_Int
for (size_t i = 0; i < maAttributeTokens.size(); ++i)
if (maAttributeTokens[i] == Token)
return FastTokenHandlerBase::getTokenFromChars(
- mxTokenHandler, mpTokenHandler,
+ mpTokenHandler,
getFastAttributeValue(i),
AttributeValueLength( i ) );
@@ -265,7 +263,6 @@ FastAttributeList::FastAttributeIter FastAttributeList::find( sal_Int32 nToken )
}
sal_Int32 FastTokenHandlerBase::getTokenFromChars(
- const css::uno::Reference< css::xml::sax::XFastTokenHandler > &xTokenHandler,
const FastTokenHandlerBase *pTokenHandler,
const char *pToken, size_t nLen /* = 0 */ )
{
@@ -274,14 +271,7 @@ sal_Int32 FastTokenHandlerBase::getTokenFromChars(
if( !nLen )
nLen = strlen( pToken );
- if( pTokenHandler )
- nRet = pTokenHandler->getTokenDirect( pToken, static_cast<sal_Int32>(nLen) );
- else
- {
- // heap allocate, copy & then free
- Sequence< sal_Int8 > aSeq( reinterpret_cast<sal_Int8 const *>(pToken), nLen );
- nRet = xTokenHandler->getTokenFromUTF8( aSeq );
- }
+ nRet = pTokenHandler->getTokenDirect( pToken, static_cast<sal_Int32>(nLen) );
return nRet;
}
diff --git a/sax/source/tools/fshelper.cxx b/sax/source/tools/fshelper.cxx
index 0d265fe36d24..41857c95ef19 100644
--- a/sax/source/tools/fshelper.cxx
+++ b/sax/source/tools/fshelper.cxx
@@ -149,7 +149,7 @@ void FastSerializerHelper::mergeTopMarks(
FastAttributeList * FastSerializerHelper::createAttrList()
{
- return new FastAttributeList( Reference< xml::sax::XFastTokenHandler >() );
+ return new FastAttributeList( nullptr );
}