[meld] misc: Fix performance of interval merging (bgo#768300)
- From: Kai Willadsen <kaiw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [meld] misc: Fix performance of interval merging (bgo#768300)
- Date: Sat, 2 Jul 2016 00:37:08 +0000 (UTC)
commit 8f2dcd1baceb8f297f67f550c6c707e72d3749d1
Author: Kai Willadsen <kai willadsen gmail com>
Date: Sat Jul 2 08:28:05 2016 +1000
misc: Fix performance of interval merging (bgo#768300)
Interval merge was constantly pop()ing from the list head, which is very
slow on standard Python lists. Just moving to a deque gets rid of this
from profiles on large lists of ignored intervals.
meld/misc.py | 7 ++++---
1 files changed, 4 insertions(+), 3 deletions(-)
---
diff --git a/meld/misc.py b/meld/misc.py
index aa13538..60b5eef 100644
--- a/meld/misc.py
+++ b/meld/misc.py
@@ -18,6 +18,7 @@
"""Module of commonly used helper classes and functions
"""
+import collections
import os
import errno
import shutil
@@ -480,12 +481,12 @@ def merge_intervals(interval_list):
if len(interval_list) < 2:
return interval_list
- interval_list.sort()
- merged_intervals = [interval_list.pop(0)]
+ interval_list = collections.deque(sorted(interval_list))
+ merged_intervals = [interval_list.popleft()]
current_start, current_end = merged_intervals[-1]
while interval_list:
- new_start, new_end = interval_list.pop(0)
+ new_start, new_end = interval_list.popleft()
if current_end >= new_end:
continue
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]