Make SvXMLTokenMap compatible with FastTokens:
Added seperate map for fastToken and Token, to get token using only fastToken. Default values are derived for fastTokens from prefixKey and localName. Duplicate/ dummy tokens need to be overidden with different values. Change-Id: I17268754d8fd1bac29dd7bae05706ff20b8314ae Reviewed-on: https://gerrit.libreoffice.org/28415 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
This commit is contained in:
parent
301279ea15
commit
41b3fd8ca5
@ -61,6 +61,8 @@
|
||||
#include <o3tl/typed_flags_set.hxx>
|
||||
#include <memory>
|
||||
|
||||
#define NAMESPACE_TOKEN( prefixToken ) ( ( prefixToken + 1 ) << NMSP_SHIFT )
|
||||
|
||||
const size_t NMSP_SHIFT = 16;
|
||||
const sal_Int32 TOKEN_MASK = 0xffff;
|
||||
const sal_Int32 NMSP_MASK = 0xffff0000;
|
||||
|
@ -28,7 +28,6 @@
|
||||
|
||||
|
||||
class SvXMLTokenMap_Impl;
|
||||
class SvXMLTokenMapEntry_Impl;
|
||||
|
||||
#define XML_TOK_UNKNOWN 0xffffU
|
||||
#define XML_TOKEN_MAP_END { 0xffffU, xmloff::token::XML_TOKEN_INVALID, 0U, 0 }
|
||||
@ -41,19 +40,21 @@ struct SvXMLTokenMapEntry
|
||||
sal_Int32 nFastToken;
|
||||
|
||||
SvXMLTokenMapEntry( sal_uInt16 nPrefix, xmloff::token::XMLTokenEnum eName,
|
||||
sal_uInt16 nTok = XML_TOK_UNKNOWN, sal_Int32 nFastTok = 0 ) :
|
||||
sal_uInt16 nTok, sal_Int32 nFastTok = 0 ) :
|
||||
nPrefixKey( nPrefix ),
|
||||
eLocalName( eName ),
|
||||
nToken( nTok ),
|
||||
nFastToken( nFastTok )
|
||||
{}
|
||||
nFastToken( ( nPrefixKey + 1 ) << 16 | eLocalName )
|
||||
{
|
||||
if ( nFastTok ) // alternative value for duplicate/dummy tokens
|
||||
nFastToken = nFastTok;
|
||||
}
|
||||
};
|
||||
|
||||
class XMLOFF_DLLPUBLIC SvXMLTokenMap
|
||||
{
|
||||
private:
|
||||
std::unique_ptr<SvXMLTokenMap_Impl> m_pImpl;
|
||||
sal_uInt16 Get( const SvXMLTokenMapEntry_Impl& rEntry ) const;
|
||||
|
||||
public:
|
||||
|
||||
|
@ -21,52 +21,63 @@
|
||||
#include <xmloff/xmltkmap.hxx>
|
||||
#include <xmloff/xmltoken.hxx>
|
||||
|
||||
#include <set>
|
||||
#include <unordered_map>
|
||||
#include <utility>
|
||||
|
||||
using namespace ::xmloff::token;
|
||||
|
||||
class SvXMLTokenMapEntry_Impl
|
||||
class SvXMLTokenMap_Impl
|
||||
{
|
||||
sal_uInt16 nPrefixKey;
|
||||
OUString sLocalName;
|
||||
sal_uInt16 nToken;
|
||||
sal_Int32 nFastToken;
|
||||
private:
|
||||
struct PairHash
|
||||
{
|
||||
std::size_t operator()(const std::pair<sal_uInt16,OUString> &pair) const
|
||||
{
|
||||
return static_cast<std::size_t>( pair.first | pair.second.hashCode() );
|
||||
}
|
||||
};
|
||||
std::unordered_map< std::pair<sal_uInt16, OUString>,
|
||||
sal_uInt16, PairHash> m_aPrefixAndNameToTokenMap;
|
||||
std::unordered_map< sal_Int32, sal_uInt16> m_aFastTokenToTokenMap;
|
||||
|
||||
public:
|
||||
|
||||
sal_uInt16 GetToken() const { return nToken; }
|
||||
|
||||
SvXMLTokenMapEntry_Impl( sal_uInt16 nPrefix, const OUString& rLName,
|
||||
sal_uInt16 nTok = XML_TOK_UNKNOWN, sal_Int32 nFastTok = 0 ) :
|
||||
nPrefixKey( nPrefix ),
|
||||
sLocalName( rLName ),
|
||||
nToken( nTok ),
|
||||
nFastToken( nFastTok )
|
||||
{}
|
||||
|
||||
explicit SvXMLTokenMapEntry_Impl( const SvXMLTokenMapEntry& rEntry ) :
|
||||
nPrefixKey( rEntry.nPrefixKey ),
|
||||
sLocalName( GetXMLToken( rEntry.eLocalName ) ),
|
||||
nToken( rEntry.nToken ),
|
||||
nFastToken( rEntry.nFastToken )
|
||||
{}
|
||||
|
||||
bool operator<( const SvXMLTokenMapEntry_Impl& r ) const
|
||||
{
|
||||
return nPrefixKey < r.nPrefixKey ||
|
||||
( nPrefixKey == r.nPrefixKey &&
|
||||
sLocalName < r.sLocalName);
|
||||
}
|
||||
void insert( const SvXMLTokenMapEntry& rEntry );
|
||||
sal_uInt16 get( sal_uInt16 nKeyPrefix, const OUString& rLName ) const;
|
||||
sal_uInt16 get( sal_Int32 nFastTok ) const;
|
||||
};
|
||||
|
||||
class SvXMLTokenMap_Impl : public std::set<SvXMLTokenMapEntry_Impl> {};
|
||||
void SvXMLTokenMap_Impl::insert( const SvXMLTokenMapEntry& rEntry )
|
||||
{
|
||||
m_aPrefixAndNameToTokenMap.insert( std::make_pair( std::make_pair( rEntry.nPrefixKey,
|
||||
GetXMLToken( rEntry.eLocalName ) ), rEntry.nToken ) );
|
||||
if( rEntry.nFastToken )
|
||||
m_aFastTokenToTokenMap.insert( std::make_pair( rEntry.nFastToken, rEntry.nToken ) );
|
||||
}
|
||||
|
||||
sal_uInt16 SvXMLTokenMap_Impl::get( sal_uInt16 nKeyPrefix, const OUString& rLName ) const
|
||||
{
|
||||
auto aIter( m_aPrefixAndNameToTokenMap.find( std::make_pair( nKeyPrefix, rLName ) ) );
|
||||
if ( aIter != m_aPrefixAndNameToTokenMap.end() )
|
||||
return (*aIter).second;
|
||||
else
|
||||
return XML_TOK_UNKNOWN;
|
||||
}
|
||||
|
||||
sal_uInt16 SvXMLTokenMap_Impl::get( sal_Int32 nFastTok ) const
|
||||
{
|
||||
auto aIter( m_aFastTokenToTokenMap.find( nFastTok ) );
|
||||
if ( aIter != m_aFastTokenToTokenMap.end() )
|
||||
return (*aIter).second;
|
||||
else
|
||||
return XML_TOK_UNKNOWN;
|
||||
}
|
||||
|
||||
SvXMLTokenMap::SvXMLTokenMap( const SvXMLTokenMapEntry *pMap )
|
||||
: m_pImpl( new SvXMLTokenMap_Impl )
|
||||
{
|
||||
while( pMap->eLocalName != XML_TOKEN_INVALID )
|
||||
{
|
||||
m_pImpl->insert(SvXMLTokenMapEntry_Impl( *pMap ));
|
||||
m_pImpl->insert( *pMap );
|
||||
pMap++;
|
||||
}
|
||||
}
|
||||
@ -75,33 +86,15 @@ SvXMLTokenMap::~SvXMLTokenMap()
|
||||
{
|
||||
}
|
||||
|
||||
sal_uInt16 SvXMLTokenMap::Get( const SvXMLTokenMapEntry_Impl& rEntry ) const
|
||||
{
|
||||
SvXMLTokenMapEntry_Impl const* pEntry = nullptr;
|
||||
SvXMLTokenMap_Impl::iterator it = m_pImpl->find( rEntry );
|
||||
if (it != m_pImpl->end())
|
||||
{
|
||||
pEntry = &*it;
|
||||
}
|
||||
|
||||
if( pEntry )
|
||||
return pEntry->GetToken();
|
||||
else
|
||||
return XML_TOK_UNKNOWN;
|
||||
}
|
||||
|
||||
sal_uInt16 SvXMLTokenMap::Get( sal_uInt16 nKeyPrefix,
|
||||
const OUString& rLName ) const
|
||||
{
|
||||
SvXMLTokenMapEntry_Impl aTst( nKeyPrefix, rLName );
|
||||
return( Get( aTst ) );
|
||||
return m_pImpl->get( nKeyPrefix, rLName );
|
||||
}
|
||||
|
||||
sal_uInt16 SvXMLTokenMap::Get( sal_Int32 nFastTok ) const
|
||||
{
|
||||
static const OUString sEmptyString("");
|
||||
SvXMLTokenMapEntry_Impl aTst( 0, sEmptyString, XML_TOK_UNKNOWN, nFastTok );
|
||||
return( Get( aTst ) );
|
||||
return m_pImpl->get( nFastTok );
|
||||
}
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||
|
@ -94,7 +94,9 @@ void XMLGradientStyleImport::importXML(
|
||||
{ XML_NAMESPACE_DRAW, XML_START_INTENSITY, XML_TOK_GRADIENT_STARTINT },
|
||||
{ XML_NAMESPACE_DRAW, XML_END_INTENSITY, XML_TOK_GRADIENT_ENDINT },
|
||||
{ XML_NAMESPACE_DRAW, XML_GRADIENT_ANGLE, XML_TOK_GRADIENT_ANGLE },
|
||||
{ XML_NAMESPACE_DRAW, XML_GRADIENT_BORDER, XML_TOK_GRADIENT_BORDER },
|
||||
{ XML_NAMESPACE_DRAW, XML_GRADIENT_BORDER, XML_TOK_GRADIENT_BORDER,
|
||||
NAMESPACE_TOKEN( XML_NAMESPACE_DRAW ) | XML_BORDER },
|
||||
// XML_GRADIENT_BORDER is a duplicate of XML_BORDER
|
||||
XML_TOKEN_MAP_END
|
||||
};
|
||||
|
||||
|
@ -79,7 +79,9 @@ void XMLHatchStyleImport::importXML(
|
||||
{ XML_NAMESPACE_DRAW, XML_DISPLAY_NAME, XML_TOK_HATCH_DISPLAY_NAME },
|
||||
{ XML_NAMESPACE_DRAW, XML_STYLE, XML_TOK_HATCH_STYLE },
|
||||
{ XML_NAMESPACE_DRAW, XML_COLOR, XML_TOK_HATCH_COLOR },
|
||||
{ XML_NAMESPACE_DRAW, XML_HATCH_DISTANCE, XML_TOK_HATCH_DISTANCE },
|
||||
{ XML_NAMESPACE_DRAW, XML_HATCH_DISTANCE, XML_TOK_HATCH_DISTANCE,
|
||||
NAMESPACE_TOKEN( XML_NAMESPACE_DRAW ) | XML_DISTANCE },
|
||||
// XML_HATCH_DISTANCE is a duplicate of XML_DISTANCE
|
||||
{ XML_NAMESPACE_DRAW, XML_ROTATION, XML_TOK_HATCH_ROTATION },
|
||||
XML_TOKEN_MAP_END
|
||||
};
|
||||
|
@ -100,7 +100,9 @@ void XMLTransGradientStyleImport::importXML(
|
||||
{ XML_NAMESPACE_DRAW, XML_START, XML_TOK_GRADIENT_START },
|
||||
{ XML_NAMESPACE_DRAW, XML_END, XML_TOK_GRADIENT_END },
|
||||
{ XML_NAMESPACE_DRAW, XML_GRADIENT_ANGLE, XML_TOK_GRADIENT_ANGLE },
|
||||
{ XML_NAMESPACE_DRAW, XML_GRADIENT_BORDER, XML_TOK_GRADIENT_BORDER },
|
||||
{ XML_NAMESPACE_DRAW, XML_GRADIENT_BORDER, XML_TOK_GRADIENT_BORDER,
|
||||
NAMESPACE_TOKEN( XML_NAMESPACE_DRAW ) | XML_BORDER },
|
||||
// XML_GRADIENT_BORDER is a duplicate of XML_BORDER
|
||||
XML_TOKEN_MAP_END
|
||||
};
|
||||
|
||||
|
@ -62,7 +62,7 @@ NP_BLOCK_LIST_DUMMY
|
||||
N_BLOCK_LIST_DUMMY
|
||||
NP_MATH_DUMMY
|
||||
N_MATH_DUMMY
|
||||
VL_DUMMY
|
||||
VL
|
||||
N_VERSIONS_LIST_DUMMY
|
||||
of
|
||||
N_OF_DUMMY
|
||||
|
Loading…
x
Reference in New Issue
Block a user