[meld] Draw all same-coloured DiffMap chunks together for performance



commit 0284ef726cf961a47966d3e087d9707046427e24
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Sun Jul 8 07:23:59 2012 +1000

    Draw all same-coloured DiffMap chunks together for performance
    
    In situations with complicated DiffMaps, there is a significant
    performance cost to doing all of the colour setting and individually
    filling and stroking each chunk. This commit avoids this cost by
    pre-sorting the chunk list into blocks of the same type, allowing us
    to set up all of our paths of a single colour, and stroke/fill in one
    Cairo call.
    
    In theory, this may cause visual changes by altering the order in which
    we overwrote pixels (i.e., instead of top-to-bottom, we now do
    colour-by-colour). In practice, this was never really defined anyway.

 meld/diffmap.py |   13 ++++++++++---
 1 files changed, 10 insertions(+), 3 deletions(-)
---
diff --git a/meld/diffmap.py b/meld/diffmap.py
index d30d1e6..609138b 100644
--- a/meld/diffmap.py
+++ b/meld/diffmap.py
@@ -15,6 +15,8 @@
 ### along with this program; if not, write to the Free Software
 ### Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
+import collections
+
 import gobject
 import gtk
 
@@ -102,11 +104,16 @@ class DiffMap(gtk.DrawingArea):
 
         darken = lambda color: [x * 0.8 for x in color]
 
+        tagged_diffs = collections.defaultdict(list)
         for c, y0, y1 in self._difffunc():
-            color = self.ctab[c]
-            y0, y1 = round(y0 * height) - 0.5, round(y1 * height) - 0.5
+            tagged_diffs[c].append((y0, y1))
+
+        for tag, diffs in tagged_diffs.iteritems():
+            color = self.ctab[tag]
             context.set_source_rgb(*color)
-            context.rectangle(x0, y0, x1, int(y1 - y0))
+            for y0, y1 in diffs:
+                y0, y1 = round(y0 * height) - 0.5, round(y1 * height) - 0.5
+                context.rectangle(x0, y0, x1, y1 - y0)
             context.fill_preserve()
             context.set_source_rgb(*darken(color))
             context.stroke()



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]