diff options
author | Ashod Nakashian <ashod.nakashian@collabora.co.uk> | 2017-11-27 19:56:35 -0500 |
---|---|---|
committer | Ashod Nakashian <ashnakash@gmail.com> | 2017-11-30 07:01:35 +0100 |
commit | 551543bf359f644f727fd1aa86e2c5ae499f88ce (patch) | |
tree | 3fa7b6aa8eaae6b27311d9bc5a1054c44858be46 | |
parent | 407660a08c8df27d7cd44435eefa31bd92364a3c (diff) |
pdf: use bimap for GraphicsContext-id map
In some large PDFs the two maps for
mapping GraphicsContext to ID and finding
GraphicsContext given and ID are huge (over
160 MB in one case). By using a bimap the
footprint went down to 110 MB.
Change-Id: I59a444b5efa09fcabc26fa492de723ca063e14a4
Reviewed-on: https://gerrit.libreoffice.org/45380
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
-rw-r--r-- | sdext/source/pdfimport/tree/pdfiprocessor.cxx | 18 | ||||
-rw-r--r-- | sdext/source/pdfimport/tree/pdfiprocessor.hxx | 12 |
2 files changed, 15 insertions, 15 deletions
diff --git a/sdext/source/pdfimport/tree/pdfiprocessor.cxx b/sdext/source/pdfimport/tree/pdfiprocessor.cxx index dbc94360ca61..bf805fc2b512 100644 --- a/sdext/source/pdfimport/tree/pdfiprocessor.cxx +++ b/sdext/source/pdfimport/tree/pdfiprocessor.cxx @@ -45,7 +45,6 @@ #include <com/sun/star/geometry/RealPoint2D.hpp> #include <com/sun/star/geometry/RealRectangle2D.hpp> - using namespace com::sun::star; @@ -65,7 +64,6 @@ namespace pdfi m_aFontToId(), m_aGCStack(), m_nNextGCId( 1 ), - m_aIdToGC(), m_aGCToId(), m_aImages(), m_nPages(0), @@ -83,8 +81,7 @@ namespace pdfi GraphicsContext aDefGC; m_aGCStack.push_back( aDefGC ); - m_aIdToGC[ 0 ] = aDefGC; - m_aGCToId[ aDefGC ] = 0; + m_aGCToId.insert(GCToIdBiMap::relation(aDefGC, 0)); } void PDFIProcessor::enableToplevelText() @@ -483,13 +480,12 @@ const FontAttributes& PDFIProcessor::getFont( sal_Int32 nFontId ) const sal_Int32 PDFIProcessor::getGCId( const GraphicsContext& rGC ) { sal_Int32 nGCId = 0; - GCToIdMap::const_iterator it = m_aGCToId.find( rGC ); - if( it != m_aGCToId.end() ) + auto it = m_aGCToId.left.find( rGC ); + if( it != m_aGCToId.left.end() ) nGCId = it->second; else { - m_aGCToId[ rGC ] = m_nNextGCId; - m_aIdToGC[ m_nNextGCId ] = rGC; + m_aGCToId.insert(GCToIdBiMap::relation(rGC, m_nNextGCId)); nGCId = m_nNextGCId; m_nNextGCId++; } @@ -499,9 +495,9 @@ sal_Int32 PDFIProcessor::getGCId( const GraphicsContext& rGC ) const GraphicsContext& PDFIProcessor::getGraphicsContext( sal_Int32 nGCId ) const { - IdToGCMap::const_iterator it = m_aIdToGC.find( nGCId ); - if( it == m_aIdToGC.end() ) - it = m_aIdToGC.find( 0 ); + auto it = m_aGCToId.right.find( nGCId ); + if( it == m_aGCToId.right.end() ) + it = m_aGCToId.right.find( 0 ); return it->second; } diff --git a/sdext/source/pdfimport/tree/pdfiprocessor.hxx b/sdext/source/pdfimport/tree/pdfiprocessor.hxx index 1588b057d9c3..0225336dcf31 100644 --- a/sdext/source/pdfimport/tree/pdfiprocessor.hxx +++ b/sdext/source/pdfimport/tree/pdfiprocessor.hxx @@ -46,6 +46,9 @@ #include "treevisitorfactory.hxx" #include "genericelements.hxx" +#include <boost/bimap/bimap.hpp> +#include <boost/bimap/unordered_set_of.hpp> + namespace pdfi { @@ -170,8 +173,10 @@ namespace pdfi typedef std::unordered_map<sal_Int32,FontAttributes> IdToFontMap; typedef std::unordered_map<FontAttributes,sal_Int32,FontAttrHash> FontToIdMap; - typedef std::unordered_map<sal_Int32,GraphicsContext> IdToGCMap; - typedef std::unordered_map<GraphicsContext,sal_Int32,GraphicsContextHash> GCToIdMap; + typedef boost::bimaps::bimap< + boost::bimaps::unordered_set_of<GraphicsContext, GraphicsContextHash>, + boost::bimaps::unordered_set_of<sal_Int32> + > GCToIdBiMap; typedef std::vector<GraphicsContext> GraphicsContextStack; @@ -186,8 +191,7 @@ namespace pdfi GraphicsContextStack m_aGCStack; sal_Int32 m_nNextGCId; - IdToGCMap m_aIdToGC; - GCToIdMap m_aGCToId; + GCToIdBiMap m_aGCToId; ImageContainer m_aImages; |