8377: added sibling lookup cache

This commit is contained in:
Doug Blank 2015-08-18 11:44:06 -04:00
parent c1afa6513c
commit b601402ea5

View File

@ -982,9 +982,10 @@ class TreeBaseModel(GObject.GObject, Gtk.TreeModel, BaseModel):
""" """
Returns a path from a given node. Returns a path from a given node.
""" """
cached, value = self.get_cached_path(iter.user_data) cached, path = self.get_cached_path(iter.user_data)
if cached: if cached:
return value (treepath, pathtup) = path
return treepath
node = self.get_node_from_iter(iter) node = self.get_node_from_iter(iter)
pathlist = [] pathlist = []
while node.parent is not None: while node.parent is not None:
@ -993,16 +994,32 @@ class TreeBaseModel(GObject.GObject, Gtk.TreeModel, BaseModel):
while node is not None: while node is not None:
# Step backwards # Step backwards
nodeid = node.next if self.__reverse else node.prev nodeid = node.next if self.__reverse else node.prev
# Let's see if sibling is cached:
cached, sib_path = self.get_cached_path(nodeid)
if cached:
(sib_treepath, sib_pathtup) = sib_path
# Does it have an actual path?
if sib_pathtup:
# Compute path to here from sibling:
# parent_path + sib_path + offset
newtup = (sib_pathtup[:-1] +
(sib_pathtup[-1] + index + 2, ) +
tuple(reversed(pathlist)))
#print("computed path:", iter.user_data, newtup)
retval = Gtk.TreePath(newtup)
self.set_cached_path(iter.user_data, (retval, newtup))
return retval
node = nodeid and self.nodemap.node(nodeid) node = nodeid and self.nodemap.node(nodeid)
index += 1 index += 1
pathlist.append(index) pathlist.append(index)
node = parent node = parent
if pathlist: if pathlist:
pathlist.reverse() pathlist.reverse()
#print("actual path :", iter.user_data, tuple(pathlist))
retval = Gtk.TreePath(tuple(pathlist)) retval = Gtk.TreePath(tuple(pathlist))
else: else:
retval = None retval = None
self.set_cached_path(iter.user_data, retval) self.set_cached_path(iter.user_data, (retval, tuple(pathlist) if pathlist else None))
return retval return retval
def do_iter_next(self, iter): def do_iter_next(self, iter):