diff --git a/gramps/gui/views/treemodels/flatbasemodel.py b/gramps/gui/views/treemodels/flatbasemodel.py index ff5873876..72c77470f 100644 --- a/gramps/gui/views/treemodels/flatbasemodel.py +++ b/gramps/gui/views/treemodels/flatbasemodel.py @@ -200,7 +200,7 @@ class FlatNodeMap(object): else: self.__corr = (0, 1) if not self._hndl2index: - self._hndl2index = dict([key[1], index] + self._hndl2index = dict((key[1], index) for index, key in enumerate(self._index2hndl)) def real_path(self, index): @@ -398,14 +398,8 @@ class FlatNodeMap(object): insert_pos = bisect.bisect_left(self._index2hndl, srtkey_hndl) self._index2hndl.insert(insert_pos, srtkey_hndl) #make sure the index map is updated - if sys.version_info[0] < 3: # keep this, for speed in Python2 - for hndl, index in self._hndl2index.iteritems(): # in Python2 "if" - if index >= insert_pos: - self._hndl2index[hndl] += 1 - else: - for hndl, index in self._hndl2index.items(): - if index >= insert_pos: - self._hndl2index[hndl] += 1 + for srt_key,hndl in self._index2hndl[insert_pos+1:]: + self._hndl2index[hndl] += 1 self._hndl2index[srtkey_hndl[1]] = insert_pos #update self.__corr so it remains correct if self._reverse: @@ -447,14 +441,8 @@ class FlatNodeMap(object): if self._reverse: self.__corr = (len(self._index2hndl) - 1, -1) #update the handle2path map so it remains correct - if sys.version_info[0] < 3: # keep this, for speed in Python2 - for key, val in self._hndl2index.iteritems(): # in Python2 "if" - if val > index: - self._hndl2index[key] -= 1 - else: - for key, val in self._hndl2index.items(): - if val > index: - self._hndl2index[key] -= 1 + for srt_key,hndl in self._index2hndl[index:]: + self._hndl2index[hndl] -= 1 return Gtk.TreePath((delpath,)) #-------------------------------------------------------------------------