sdext/source/pdfimport/tree/pdfiprocessor.cxx |   18 +++++++-----------
 sdext/source/pdfimport/tree/pdfiprocessor.hxx |   12 ++++++++----
 2 files changed, 15 insertions(+), 15 deletions(-)

New commits:
commit 551543bf359f644f727fd1aa86e2c5ae499f88ce
Author: Ashod Nakashian <ashod.nakash...@collabora.co.uk>
Date:   Mon Nov 27 19:56:35 2017 -0500

    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 <ashnak...@gmail.com>
    Tested-by: Ashod Nakashian <ashnak...@gmail.com>

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;
 
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to