kbrown / rpms / libreoffice

Forked from rpms/libreoffice 2 years ago
Clone

Blame SOURCES/0013-lokdocview-Use-maps-instead-of-vector.patch

f325b2
From a8675df04f316dce72483c62f578467dfb446493 Mon Sep 17 00:00:00 2001
f325b2
From: Pranav Kant <pranavk@gnome.org>
f325b2
Date: Thu, 4 Jun 2015 01:44:47 +0530
f325b2
Subject: [PATCH 013/398] lokdocview: Use maps instead of vector
f325b2
f325b2
Using vector each tile needs to be allocated memory irrespective of
f325b2
whether tile is required or not. This approach fails when we zoom in to
f325b2
a very high level to have thousands of tiles due to lot of memory
f325b2
required. Using maps instead of vector takes care of this, and only
f325b2
allocates Tiles when required.
f325b2
f325b2
Change-Id: I523f815618451a7f014e28258e0de7b1c0693370
f325b2
(cherry picked from commit cc78267f274a42d268b1d56d0a83888dc69a4c91)
f325b2
---
f325b2
 libreofficekit/source/gtk/tilebuffer.cxx | 17 +++++++++--------
f325b2
 libreofficekit/source/gtk/tilebuffer.hxx |  8 +++-----
f325b2
 2 files changed, 12 insertions(+), 13 deletions(-)
f325b2
f325b2
diff --git a/libreofficekit/source/gtk/tilebuffer.cxx b/libreofficekit/source/gtk/tilebuffer.cxx
f325b2
index ca66ae904f71..e1b5b3294cc5 100644
f325b2
--- a/libreofficekit/source/gtk/tilebuffer.cxx
f325b2
+++ b/libreofficekit/source/gtk/tilebuffer.cxx
f325b2
@@ -41,22 +41,22 @@ void TileBuffer::tile_buffer_set_zoom(float newZoomFactor, int rows, int columns
f325b2
   // set new buffer width and height
f325b2
   m_nWidth = columns;
f325b2
   m_nHeight = rows;
f325b2
-  m_aTiles.resize(m_nWidth * m_nHeight);
f325b2
 }
f325b2
 
f325b2
 void TileBuffer::tile_buffer_reset_all_tiles()
f325b2
 {
f325b2
-  for (size_t i = 0; i < m_aTiles.size(); i++)
f325b2
+  std::map<int, Tile>::iterator it = m_mTiles.begin();
f325b2
+  for (; it != m_mTiles.end(); it++)
f325b2
     {
f325b2
-      m_aTiles[i].tile_release();
f325b2
+       it->second.tile_release();
f325b2
     }
f325b2
-  m_aTiles.clear();
f325b2
+  m_mTiles.clear();
f325b2
 }
f325b2
 
f325b2
 Tile& TileBuffer::tile_buffer_get_tile(int x, int y)
f325b2
 {
f325b2
   int index = x * m_nWidth + y;
f325b2
-  if(!m_aTiles[index].valid)
f325b2
+  if(m_mTiles.find(index) == m_mTiles.end())
f325b2
     {
f325b2
       GdkPixbuf* pPixBuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, m_nTileSize, m_nTileSize);
f325b2
       if (!pPixBuf){
f325b2
@@ -77,11 +77,12 @@ Tile& TileBuffer::tile_buffer_get_tile(int x, int y)
f325b2
                                         // Size of the tile, depends on the zoom factor and the tile position only.
f325b2
                                         pixelToTwip(m_nTileSize, m_fZoomFactor), pixelToTwip(m_nTileSize, m_fZoomFactor));
f325b2
 
f325b2
-      m_aTiles[index].tile_set_pixbuf(pPixBuf);
f325b2
-      m_aTiles[index].valid = 1;
f325b2
+      //create a mapping for it
f325b2
+      m_mTiles[index].tile_set_pixbuf(pPixBuf);
f325b2
+      m_mTiles[index].valid = 1;
f325b2
     }
f325b2
 
f325b2
-  return m_aTiles[index];
f325b2
+  return m_mTiles[index];
f325b2
 }
f325b2
 
f325b2
 void Tile::tile_set_pixbuf(GdkPixbuf *buffer)
f325b2
diff --git a/libreofficekit/source/gtk/tilebuffer.hxx b/libreofficekit/source/gtk/tilebuffer.hxx
f325b2
index a5ed0dc8ec61..0bc2d38dd641 100644
f325b2
--- a/libreofficekit/source/gtk/tilebuffer.hxx
f325b2
+++ b/libreofficekit/source/gtk/tilebuffer.hxx
f325b2
@@ -12,7 +12,7 @@
f325b2
 
f325b2
 #include <gdk/gdkkeysyms.h>
f325b2
 #include <gdk-pixbuf/gdk-pixbuf.h>
f325b2
-#include <vector>
f325b2
+#include <map>
f325b2
 
f325b2
 #define LOK_USE_UNSTABLE_API
f325b2
 #include <LibreOfficeKit/LibreOfficeKit.h>
f325b2
@@ -55,9 +55,7 @@ public:
f325b2
     , m_fZoomFactor(1)
f325b2
     , m_nWidth(columns)
f325b2
     , m_nHeight(rows)
f325b2
-  {
f325b2
-    m_aTiles.resize(rows * columns);
f325b2
-  }
f325b2
+    {  }
f325b2
 
f325b2
   ~TileBuffer() {}
f325b2
 
f325b2
@@ -69,7 +67,7 @@ private:
f325b2
   LibreOfficeKitDocument *m_pLOKDocument;
f325b2
   int m_nTileSize;
f325b2
   float m_fZoomFactor;
f325b2
-  std::vector<Tile> m_aTiles;
f325b2
+  std::map<int, Tile> m_mTiles;
f325b2
   //TODO: Also set width and height when document size changes
f325b2
   int m_nWidth;
f325b2
   int m_nHeight;
f325b2
-- 
f325b2
2.12.0
f325b2