diff options
author | Mohammed Abdul Azeem <azeemmysore@gmail.com> | 2016-08-26 23:32:23 +0530 |
---|---|---|
committer | Noel Grandin <noelgrandin@gmail.com> | 2016-08-29 06:22:46 +0000 |
commit | 41b3fd8ca54eff7e71c69bb0b60e63016f1ac8c2 (patch) | |
tree | e5a3af9a2f0c0a7c40333c59869fff9ee1b953e7 | |
parent | 301279ea15f0310367598300f884062333628767 (diff) |
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>
-rw-r--r-- | include/xmloff/xmlimp.hxx | 2 | ||||
-rw-r--r-- | include/xmloff/xmltkmap.hxx | 11 | ||||
-rw-r--r-- | xmloff/source/core/xmltkmap.cxx | 95 | ||||
-rw-r--r-- | xmloff/source/style/GradientStyle.cxx | 4 | ||||
-rw-r--r-- | xmloff/source/style/HatchStyle.cxx | 4 | ||||
-rw-r--r-- | xmloff/source/style/TransGradientStyle.cxx | 4 | ||||
-rw-r--r-- | xmloff/source/token/tokens.txt | 2 |
7 files changed, 62 insertions, 60 deletions
diff --git a/include/xmloff/xmlimp.hxx b/include/xmloff/xmlimp.hxx index a1152c4962d7..c673dfc1f86a 100644 --- a/include/xmloff/xmlimp.hxx +++ b/include/xmloff/xmlimp.hxx @@ -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; diff --git a/include/xmloff/xmltkmap.hxx b/include/xmloff/xmltkmap.hxx index c54d8012c682..2953dac755d7 100644 --- a/include/xmloff/xmltkmap.hxx +++ b/include/xmloff/xmltkmap.hxx @@ -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: diff --git a/xmloff/source/core/xmltkmap.cxx b/xmloff/source/core/xmltkmap.cxx index 6888b62aae60..1aca38975d9b 100644 --- a/xmloff/source/core/xmltkmap.cxx +++ b/xmloff/source/core/xmltkmap.cxx @@ -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: + void insert( const SvXMLTokenMapEntry& rEntry ); + sal_uInt16 get( sal_uInt16 nKeyPrefix, const OUString& rLName ) const; + sal_uInt16 get( sal_Int32 nFastTok ) const; +}; - 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 ) - {} +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 ) ); +} - bool operator<( const SvXMLTokenMapEntry_Impl& r ) const - { - return nPrefixKey < r.nPrefixKey || - ( nPrefixKey == r.nPrefixKey && - sLocalName < r.sLocalName); - } -}; +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; +} -class SvXMLTokenMap_Impl : public std::set<SvXMLTokenMapEntry_Impl> {}; +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: */ diff --git a/xmloff/source/style/GradientStyle.cxx b/xmloff/source/style/GradientStyle.cxx index fd72968f93a3..ac05a0dbacee 100644 --- a/xmloff/source/style/GradientStyle.cxx +++ b/xmloff/source/style/GradientStyle.cxx @@ -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 }; diff --git a/xmloff/source/style/HatchStyle.cxx b/xmloff/source/style/HatchStyle.cxx index 43c1e029e953..ea7999f0ac27 100644 --- a/xmloff/source/style/HatchStyle.cxx +++ b/xmloff/source/style/HatchStyle.cxx @@ -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 }; diff --git a/xmloff/source/style/TransGradientStyle.cxx b/xmloff/source/style/TransGradientStyle.cxx index ab193f1a4895..5a9d93d0f94a 100644 --- a/xmloff/source/style/TransGradientStyle.cxx +++ b/xmloff/source/style/TransGradientStyle.cxx @@ -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 }; diff --git a/xmloff/source/token/tokens.txt b/xmloff/source/token/tokens.txt index d93d50a8053f..1a1db7bcdaeb 100644 --- a/xmloff/source/token/tokens.txt +++ b/xmloff/source/token/tokens.txt @@ -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 |