[codeface] [PATCH 05/26] Sort line information in FileDict

  • From: Claus Hunsen <hunsen@xxxxxxxxxxxxxxxxx>
  • To: codeface@xxxxxxxxxxxxx
  • Date: Thu, 13 Oct 2016 17:29:37 +0200

When rewriting the data structure, it can occur that the lines in the
'line_list' list are not properly sorted. To ensure reliability for the
'bisect_right' call in the 'get_line_info_raw', the list is now sorted
after each insertion.

Signed-off-by: Claus Hunsen <hunsen@xxxxxxxxxxxxxxxxx>
---
 codeface/fileCommit.py | 1 +
 1 file changed, 1 insertion(+)

diff --git a/codeface/fileCommit.py b/codeface/fileCommit.py
index c6b530a..8aaf5e0 100644
--- a/codeface/fileCommit.py
+++ b/codeface/fileCommit.py
@@ -78,6 +78,7 @@ class FileDict:
         if line_nr < self.lastItem:
             raise ValueError("can only incrementally add items")
         self.line_list.append(line_nr)
+        self.line_list.sort()  # make sure the lines are properly sorted
         self.line_dict[line_nr] = info
 
     def values(self):
-- 
2.10.0


Other related posts: