[PATCH] Some minor fixes and improvements
- From: Piotr Piastucki <leech miranda gmail com>
- To: meld-list <meld-list gnome org>
- Subject: [PATCH] Some minor fixes and improvements
- Date: Fri, 25 Feb 2011 10:39:32 +0100
Hi,
I am sending the following 2 patches:
1) 0001-Workaround-for-line-numbers-covering-issue-610376.patch
This patch tries to work around the issue #610376, I have also attached
it to the ticket in Bugzilla. It is rather a workaround than a real fix,
but it seems to work reasonably well.
2) 0002-Myers-matcher-performance-improvements-and-cleanup.patch
Some minor performance improvements and cleaunp in Myers matcher code.
Comments and testing welcome.
Cheers,
Piotr
>From bacfe9835fabb7888c2a5b64ed75b4cd5cce7382 Mon Sep 17 00:00:00 2001
From: Piotr Piastucki <the_leech users berlios de>
Date: Fri, 25 Feb 2011 10:17:19 +0100
Subject: [PATCH 2/2] Myers matcher performance improvements and cleanup
This patch slightly simplifies the code of Myers matcher and improves the performance up to 10%.
---
meld/matchers.py | 61 +++++++++++++++++++++++-------------------------------
1 files changed, 26 insertions(+), 35 deletions(-)
diff --git a/meld/matchers.py b/meld/matchers.py
index 19507fe..ffd9f3a 100644
--- a/meld/matchers.py
+++ b/meld/matchers.py
@@ -105,12 +105,8 @@ class MyersSequenceMatcher(difflib.SequenceMatcher):
# discard lines that do not match any line from the other file
if n > 0 and m > 0:
- aset = set()
- bset = set()
- for newline in b:
- bset.add(newline)
- for newline in a:
- aset.add(newline)
+ aset = frozenset(a)
+ bset = frozenset(b)
a2 = []
b2 = []
j = 0
@@ -204,7 +200,7 @@ class MyersSequenceMatcher(difflib.SequenceMatcher):
def initialise(self):
"""
- Optimized implementaion of the O(NP) algorithm described by Sun Wu, Udi Manber, Gene Myers, Webb Miller
+ Optimized implementation of the O(NP) algorithm described by Sun Wu, Udi Manber, Gene Myers, Webb Miller
("An O(NP) Sequence Comparison Algorithm", 1989)
http://research.janelia.org/myers/Papers/np_diff.pdf
"""
@@ -214,10 +210,9 @@ class MyersSequenceMatcher(difflib.SequenceMatcher):
n = len(b)
middle = m + 1
lastsnake = None
- delta = n - m
- dmin = min(0, delta)
- dmax = max(0, delta)
-
+ delta = n - m + middle
+ dmin = min(middle, delta)
+ dmax = max(middle, delta)
snakes = []
if n > 0 and m > 0:
size = n + m + 2
@@ -230,57 +225,53 @@ class MyersSequenceMatcher(difflib.SequenceMatcher):
# move along vertical edge
yv = -1
node = None
- for k in range(dmin - p, delta, 1):
- km = k + middle
- if yv < fp[km + 1][0]:
- yv, node = fp[km + 1]
+ for km in range(dmin - p, delta, 1):
+ t = fp[km + 1]
+ if yv < t[0]:
+ yv, node = t
else:
yv += 1
- x = yv - k
- snake = 0
+ snake = x = yv - km + middle
while x < m and yv < n and a[x] == b[yv]:
x += 1
yv += 1
- snake += 1
- if snake:
+ if x != snake:
+ snake = x - snake
snakes.append((node, x - snake, yv - snake, snake))
node = len(snakes) - 1
fp[km] = (yv, node)
# move along horizontal edge
yh = -1
node = None
- for k in range(dmax + p, delta, -1):
- km = k + middle
- if fp[km - 1][0] >= yh:
- yh, node = fp[km - 1]
+ for km in range(dmax + p, delta, -1):
+ t = fp[km - 1]
+ if yh <= t[0]:
+ yh, node = t
yh += 1
- x = yh - k
- snake = 0
+ snake = x = yh - km + middle
while x < m and yh < n and a[x] == b[yh]:
x += 1
yh += 1
- snake += 1
- if snake:
+ if x != snake:
+ snake = x - snake
snakes.append((node, x - snake, yh - snake, snake))
node = len(snakes) - 1
fp[km] = (yh, node)
# point on the diagonal that leads to the sink
- km = delta + middle
if yv < yh:
- y, node = fp[km + 1]
+ y, node = fp[delta + 1]
else:
- y, node = fp[km - 1]
+ y, node = fp[delta - 1]
y += 1
- x = y - delta
- snake = 0
+ snake = x = y - delta + middle
while x < m and y < n and a[x] == b[y]:
x += 1
y += 1
- snake += 1
- if snake:
+ if x != snake:
+ snake = x - snake
snakes.append((node, x - snake, y - snake, snake))
node = len(snakes) - 1
- fp[km] = (y, node)
+ fp[delta] = (y, node)
if y >= n:
lastsnake = node
break
--
1.7.1
>From 7ec9def900e4d756e9bcc6769f3693860e9adb8d Mon Sep 17 00:00:00 2001
From: Piotr Piastucki <the_leech users berlios de>
Date: Sat, 19 Feb 2011 12:12:58 +0100
Subject: [PATCH 1/2] Workaround for line numbers covering issue (#610376)
Both meld and gtksourceviewgutter handle expose-event to draw gutter content,
however, gtksourceviewgutter handler gets invoked first.
There seems to be no way to change the order of GTK signal handlers, so another
expose-event is emitted again after diff coloured block is drawn to trigger
gtksourceviewgutter handler.
---
meld/filediff.py | 10 ++++++++++
1 files changed, 10 insertions(+), 0 deletions(-)
diff --git a/meld/filediff.py b/meld/filediff.py
index f053218..e8b409e 100644
--- a/meld/filediff.py
+++ b/meld/filediff.py
@@ -230,6 +230,7 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
self.linediffer = self.differ()
self.linediffer.ignore_blanks = self.prefs.ignore_blank_lines
self.in_nested_action = False
+ self.in_nested_textview_gutter_expose = False
self._inline_cache = set()
self._cached_match = CachedSequenceMatcher()
for buf in self.textbuffer:
@@ -1085,6 +1086,11 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
if event.window != textview.get_window(gtk.TEXT_WINDOW_TEXT) \
and event.window != textview.get_window(gtk.TEXT_WINDOW_LEFT):
return
+
+ if event.window == textview.get_window(gtk.TEXT_WINDOW_LEFT) and self.in_nested_textview_gutter_expose:
+ self.in_nested_textview_gutter_expose = False
+ return
+
visible = textview.get_visible_rect()
pane = self.textview.index(textview)
area = event.area
@@ -1121,6 +1127,10 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
context.rectangle(0, ypos - visible.y, width, line_height)
context.fill()
+ if event.window == textview.get_window(gtk.TEXT_WINDOW_LEFT):
+ self.in_nested_textview_gutter_expose = True
+ textview.emit("expose-event", event)
+
def _get_filename_for_saving(self, title ):
dialog = gtk.FileChooserDialog(title,
parent=self.widget.get_toplevel(),
--
1.7.1
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]