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>
This commit is contained in:
parent
af9642350d
commit
0dbc76a3ca
18 changed files with 54 additions and 61 deletions
|
@ -30,8 +30,7 @@ enum SvXMLAutoCorrectToken : sal_Int32
|
|||
NAME = FastToken::NAMESPACE | XML_NAMESPACE_BLOCKLIST | XML_NAME //66737
|
||||
};
|
||||
|
||||
class SvXMLAutoCorrectTokenHandler : public
|
||||
cppu::WeakImplHelper< css::xml::sax::XFastTokenHandler >,
|
||||
class SvXMLAutoCorrectTokenHandler :
|
||||
public sax_fastparser::FastTokenHandlerBase
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -40,9 +40,7 @@ namespace core {
|
|||
that provides access to the tokens generated from the internal token name list.
|
||||
*/
|
||||
class OOX_DLLPUBLIC FastTokenHandler final :
|
||||
public ::cppu::WeakImplHelper< css::lang::XServiceInfo,
|
||||
css::xml::sax::XFastTokenHandler >,
|
||||
public sax_fastparser::FastTokenHandlerBase
|
||||
public cppu::ImplInheritanceHelper< sax_fastparser::FastTokenHandlerBase, css::lang::XServiceInfo >
|
||||
{
|
||||
public:
|
||||
explicit FastTokenHandler();
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#define INCLUDED_SAX_FASTATTRIBS_HXX
|
||||
|
||||
#include <com/sun/star/xml/sax/XFastAttributeList.hpp>
|
||||
#include <com/sun/star/xml/sax/XFastTokenHandler.hpp>
|
||||
|
||||
#include <cppuhelper/implbase.hxx>
|
||||
#include <sax/saxdllapi.h>
|
||||
|
@ -49,7 +50,8 @@ struct UnknownAttribute
|
|||
typedef std::vector< UnknownAttribute > UnknownAttributeList;
|
||||
|
||||
/// A native C++ interface to tokenisation
|
||||
class SAX_DLLPUBLIC FastTokenHandlerBase
|
||||
class SAX_DLLPUBLIC FastTokenHandlerBase :
|
||||
public cppu::WeakImplHelper< css::xml::sax::XFastTokenHandler >
|
||||
{
|
||||
public:
|
||||
virtual ~FastTokenHandlerBase();
|
||||
|
@ -57,24 +59,21 @@ class SAX_DLLPUBLIC FastTokenHandlerBase
|
|||
|
||||
/**
|
||||
* Client method to attempt the use of this interface if possible.
|
||||
* @xTokenHandler - the UNO handle for the token lookup interface
|
||||
* @pTokenHandler - a dynamic_cast version of @xTokenHandler to this interface
|
||||
* @xTokenHandler - the token lookup interface
|
||||
* @pStr - string buffer to lookup
|
||||
* @nLength - optional length of chars in that buffer
|
||||
*
|
||||
* @return Tokenized form of pStr
|
||||
*/
|
||||
static sal_Int32 getTokenFromChars(
|
||||
const css::uno::Reference<css::xml::sax::XFastTokenHandler > &xTokenHandler,
|
||||
const FastTokenHandlerBase *pTokenHandler /* can be NULL */,
|
||||
const FastTokenHandlerBase *pTokenHandler,
|
||||
const char *pStr, size_t nLength );
|
||||
};
|
||||
|
||||
class SAX_DLLPUBLIC FastAttributeList final : public cppu::WeakImplHelper< css::xml::sax::XFastAttributeList >
|
||||
{
|
||||
public:
|
||||
FastAttributeList( const css::uno::Reference< css::xml::sax::XFastTokenHandler >& xTokenHandler,
|
||||
FastTokenHandlerBase *pOptHandlerBase = nullptr );
|
||||
FastAttributeList( FastTokenHandlerBase *pTokenHandler );
|
||||
virtual ~FastAttributeList() override;
|
||||
|
||||
void clear();
|
||||
|
@ -208,8 +207,7 @@ private:
|
|||
std::vector< sal_Int32 > maAttributeValues;
|
||||
std::vector< sal_Int32 > maAttributeTokens;
|
||||
UnknownAttributeList maUnknownAttributes;
|
||||
css::uno::Reference< css::xml::sax::XFastTokenHandler > mxTokenHandler;
|
||||
FastTokenHandlerBase *mpTokenHandler;
|
||||
FastTokenHandlerBase * mpTokenHandler;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -76,7 +76,7 @@ extern "C" SAL_DLLPUBLIC_EXPORT uno::XInterface*
|
|||
com_sun_star_comp_oox_core_FastTokenHandler_get_implementation(
|
||||
uno::XComponentContext* /*pCtx*/, uno::Sequence<uno::Any> const& /*rSeq*/)
|
||||
{
|
||||
return cppu::acquire(new oox::core::FastTokenHandler());
|
||||
return cppu::acquire(static_cast<sax_fastparser::FastTokenHandlerBase*>(new oox::core::FastTokenHandler()));
|
||||
}
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include <filter/msfilter/mscodec.hxx>
|
||||
#include <tools/stream.hxx>
|
||||
#include <tools/XmlWriter.hxx>
|
||||
#include <sax/fastattribs.hxx>
|
||||
|
||||
#include <com/sun/star/xml/sax/XFastParser.hpp>
|
||||
#include <com/sun/star/xml/sax/XFastTokenHandler.hpp>
|
||||
|
@ -48,7 +49,7 @@ OUString stripNamespacePrefix(OUString const & rsInputName)
|
|||
return rsInputName.copy(rsInputName.indexOf(":") + 1);
|
||||
}
|
||||
|
||||
class AgileTokenHandler : public cppu::WeakImplHelper<XFastTokenHandler>
|
||||
class AgileTokenHandler : public sax_fastparser::FastTokenHandlerBase
|
||||
{
|
||||
public:
|
||||
virtual sal_Int32 SAL_CALL getTokenFromUTF8(const Sequence< sal_Int8 >& /*nIdentifier*/) override
|
||||
|
@ -60,6 +61,11 @@ public:
|
|||
{
|
||||
return Sequence<sal_Int8>();
|
||||
}
|
||||
|
||||
virtual sal_Int32 getTokenDirect( const char * /* pToken */, sal_Int32 /* nLength */ ) const override
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
};
|
||||
|
||||
class AgileDocumentHandler : public ::cppu::WeakImplHelper<XFastDocumentHandler>
|
||||
|
|
|
@ -22,6 +22,7 @@ $(eval $(call gb_CppunitTest_use_libraries,sax_parser, \
|
|||
unotest \
|
||||
expwrap \
|
||||
sal \
|
||||
sax \
|
||||
test \
|
||||
))
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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[];
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -149,7 +149,7 @@ void FastSerializerHelper::mergeTopMarks(
|
|||
|
||||
FastAttributeList * FastSerializerHelper::createAttrList()
|
||||
{
|
||||
return new FastAttributeList( Reference< xml::sax::XFastTokenHandler >() );
|
||||
return new FastAttributeList( nullptr );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -85,8 +85,7 @@ enum SwXMLTextBlockToken : sal_Int32
|
|||
TEXT_P = FastToken::NAMESPACE | XML_NAMESPACE_TEXT | XML_P
|
||||
};
|
||||
|
||||
class SwXMLTextBlockTokenHandler : public
|
||||
cppu::WeakImplHelper< css::xml::sax::XFastTokenHandler >,
|
||||
class SwXMLTextBlockTokenHandler :
|
||||
public sax_fastparser::FastTokenHandlerBase
|
||||
{
|
||||
public:
|
||||
|
@ -112,8 +111,7 @@ enum SwXMLBlockListToken : sal_Int32
|
|||
UNFORMATTED_TEXT = FastToken::NAMESPACE | XML_NAMESPACE_BLOCKLIST | XML_UNFORMATTED_TEXT
|
||||
};
|
||||
|
||||
class SwXMLBlockListTokenHandler : public
|
||||
cppu::WeakImplHelper< css::xml::sax::XFastTokenHandler >,
|
||||
class SwXMLBlockListTokenHandler :
|
||||
public sax_fastparser::FastTokenHandlerBase
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -34,6 +34,7 @@ $(eval $(call gb_CppunitTest_use_libraries,unoxml_domtest, \
|
|||
cppu \
|
||||
cppuhelper \
|
||||
sal \
|
||||
sax \
|
||||
test \
|
||||
unotest \
|
||||
))
|
||||
|
|
|
@ -50,13 +50,13 @@ namespace DOM
|
|||
struct Context
|
||||
{
|
||||
Context( const css::uno::Reference< css::xml::sax::XFastDocumentHandler >& i_xHandler,
|
||||
const css::uno::Reference< css::xml::sax::XFastTokenHandler >& i_xTokenHandler ) :
|
||||
sax_fastparser::FastTokenHandlerBase* pTokenHandler ) :
|
||||
maNamespaces( 1, std::vector<Namespace>() ),
|
||||
maNamespaceMap(101),
|
||||
mxAttribList(new sax_fastparser::FastAttributeList(i_xTokenHandler)),
|
||||
mxAttribList(new sax_fastparser::FastAttributeList(pTokenHandler)),
|
||||
mxCurrentHandler(i_xHandler),
|
||||
mxDocHandler(i_xHandler),
|
||||
mxTokenHandler(i_xTokenHandler)
|
||||
mxTokenHandler(pTokenHandler)
|
||||
{}
|
||||
|
||||
struct Namespace
|
||||
|
@ -76,7 +76,7 @@ namespace DOM
|
|||
::rtl::Reference<sax_fastparser::FastAttributeList> mxAttribList;
|
||||
css::uno::Reference<css::xml::sax::XFastContextHandler> mxCurrentHandler;
|
||||
css::uno::Reference<css::xml::sax::XFastDocumentHandler> mxDocHandler;
|
||||
css::uno::Reference<css::xml::sax::XFastTokenHandler> mxTokenHandler;
|
||||
rtl::Reference<sax_fastparser::FastTokenHandlerBase> mxTokenHandler;
|
||||
};
|
||||
|
||||
void pushContext(Context& io_rContext);
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
#include <rtl/ref.hxx>
|
||||
#include <sal/log.hxx>
|
||||
#include <sax/fastattribs.hxx>
|
||||
#include <comphelper/seqstream.hxx>
|
||||
#include <cppuhelper/implbase.hxx>
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
|
@ -168,8 +169,7 @@ struct DocumentHandler
|
|||
}
|
||||
};
|
||||
|
||||
struct TokenHandler
|
||||
: public ::cppu::WeakImplHelper< xml::sax::XFastTokenHandler >
|
||||
struct TokenHandler : public sax_fastparser::FastTokenHandlerBase
|
||||
{
|
||||
virtual ::sal_Int32 SAL_CALL getTokenFromUTF8( const uno::Sequence< ::sal_Int8 >& Identifier ) override
|
||||
{
|
||||
|
@ -182,6 +182,11 @@ struct TokenHandler
|
|||
false );
|
||||
return uno::Sequence<sal_Int8>();
|
||||
}
|
||||
|
||||
virtual sal_Int32 getTokenDirect( const char * /* pToken */, sal_Int32 /* nLength */ ) const override
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
};
|
||||
|
||||
struct BasicTest : public test::BootstrapFixture
|
||||
|
|
|
@ -1008,7 +1008,7 @@ namespace DOM
|
|||
}
|
||||
|
||||
Context aContext(i_xHandler,
|
||||
i_xTokenHandler);
|
||||
dynamic_cast<sax_fastparser::FastTokenHandlerBase*>(i_xTokenHandler.get()));
|
||||
|
||||
// register namespace ids
|
||||
for (const beans::Pair<OUString,sal_Int32>& rNs : i_rRegisterNamespaces)
|
||||
|
|
|
@ -69,8 +69,7 @@ private:
|
|||
|
||||
struct StaticTokenMap : public rtl::Static< TokenMap, StaticTokenMap > {};
|
||||
|
||||
class FastTokenHandler final : public cppu::WeakImplHelper<
|
||||
css::xml::sax::XFastTokenHandler >,
|
||||
class FastTokenHandler final :
|
||||
public sax_fastparser::FastTokenHandlerBase
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -2215,8 +2215,7 @@ OUString SvXMLImportFastNamespaceHandler::getNamespaceURI( const OUString&/* rNa
|
|||
|
||||
SvXMLLegacyToFastDocHandler::SvXMLLegacyToFastDocHandler( const rtl::Reference< SvXMLImport > & rImport )
|
||||
: mrImport( rImport ),
|
||||
mxFastAttributes( new sax_fastparser::FastAttributeList( SvXMLImport::xTokenHandler.get(),
|
||||
dynamic_cast< sax_fastparser::FastTokenHandlerBase *>( SvXMLImport::xTokenHandler.get() ) ) )
|
||||
mxFastAttributes( new sax_fastparser::FastAttributeList( SvXMLImport::xTokenHandler.get() ) )
|
||||
{
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue