Kaydet (Commit) 653736fb authored tarafından Ashod Nakashian's avatar Ashod Nakashian Kaydeden (comit) Ashod Nakashian

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/45380Reviewed-by: 's avatarAshod Nakashian <ashnakash@gmail.com>
Tested-by: 's avatarAshod Nakashian <ashnakash@gmail.com>
(cherry picked from commit 551543bf)
(cherry picked from commit ac328157)

Change-Id: I59a444b5efa09fcabc26fa492de723ca063e14a4
Reviewed-on: https://gerrit.libreoffice.org/46988Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarAshod Nakashian <ashnakash@gmail.com>
üst 5a529d17
......@@ -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;
......
......@@ -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;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment