From 7cfcc56250913b593ddb285f80972feb8602dd51 Mon Sep 17 00:00:00 2001 From: Andrew Hamilton Date: Tue, 13 Apr 2021 19:48:06 +1000 Subject: [PATCH] Coding style. - Slightly optimize add_entry by having sorted_collection.insert return where the insert was. --- eris/__main__.py | 3 +-- eris/sorted_collection.py | 7 ++++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/eris/__main__.py b/eris/__main__.py index 6b822cb..a77eff1 100755 --- a/eris/__main__.py +++ b/eris/__main__.py @@ -275,8 +275,7 @@ class Summary: Entry.MAX_WIDTH = max(len(entry), Entry.MAX_WIDTH) self._max_path_length = max(len(entry.path) - len("./"), self._max_path_length) - self._entries.insert(entry) - entry_index = self._entries.index(entry) + entry_index = self._entries.insert(entry) x, y = self._cursor_position if entry_index <= y: self.scroll(0, -1) diff --git a/eris/sorted_collection.py b/eris/sorted_collection.py index 2cc6103..7e2ce2a 100644 --- a/eris/sorted_collection.py +++ b/eris/sorted_collection.py @@ -64,7 +64,10 @@ class SortedCollection(object): ... ('bill', 'smith', 22), ... ('david', 'thomas', 32)]: ... s.insert(record) - + 0 + 0 + 0 + 3 >>> pprint(list(s)) # show records sorted by age [('bill', 'smith', 22), ('angela', 'jones', 28), @@ -167,6 +170,7 @@ class SortedCollection(object): i = bisect_left(self._keys, k) self._keys.insert(i, k) self._items.insert(i, item) + return i def insert_right(self, item): 'Insert a new item. If equal keys are found, add to the right' @@ -174,6 +178,7 @@ class SortedCollection(object): i = bisect_right(self._keys, k) self._keys.insert(i, k) self._items.insert(i, item) + return i def remove(self, item): 'Remove first occurence of item. Raise ValueError if not found'