[Libreoffice-commits] core.git: sdext/source

Ashod Nakashian ashod.nakashian at collabora.co.uk
Sun Dec 24 16:09:32 UTC 2017


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

New commits:
commit 653736fb23346e07e8c0e6e0125689ae1f49f0f7
Author: Ashod Nakashian <ashod.nakashian at 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.
    
    Reviewed-on: https://gerrit.libreoffice.org/45380
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
    Tested-by: Ashod Nakashian <ashnakash at gmail.com>
    (cherry picked from commit 551543bf359f644f727fd1aa86e2c5ae499f88ce)
    (cherry picked from commit ac328157460e9e6a9ca6834e8233a28e845c2806)
    
    Change-Id: I59a444b5efa09fcabc26fa492de723ca063e14a4
    Reviewed-on: https://gerrit.libreoffice.org/46988
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>

diff --git a/sdext/source/pdfimport/inc/pdfiprocessor.hxx b/sdext/source/pdfimport/inc/pdfiprocessor.hxx
index fae6c0fc5382..f0662b8b1ad9 100644
--- a/sdext/source/pdfimport/inc/pdfiprocessor.hxx
+++ b/sdext/source/pdfimport/inc/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
 {
 
@@ -169,6 +172,10 @@ namespace pdfi
 
         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;
 
@@ -183,8 +190,7 @@ namespace pdfi
 
         GraphicsContextStack               m_aGCStack;
         sal_Int32                          m_nNextGCId;
-        IdToGCMap                          m_aIdToGC;
-        GCToIdMap                          m_aGCToId;
+        GCToIdBiMap                        m_aGCToId;
 
         ImageContainer                     m_aImages;
 
diff --git a/sdext/source/pdfimport/tree/pdfiprocessor.cxx b/sdext/source/pdfimport/tree/pdfiprocessor.cxx
index fac0e6873638..4937e332d6f6 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),
@@ -82,8 +80,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::setPageNum( sal_Int32 nPages )
@@ -481,13 +478,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++;
     }
@@ -497,9 +493,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;
 }
 


More information about the Libreoffice-commits mailing list