Readability and performance tweaks

svn: r13767
This commit is contained in:
Gerald Britton 2009-12-11 17:30:54 +00:00
parent fae07ee445
commit 54e5538c2d
4 changed files with 14 additions and 54 deletions

View File

@ -151,10 +151,7 @@ class FlatNodeMap(object):
self._index2hndl = index2hndllist self._index2hndl = index2hndllist
self._hndl2index = {} self._hndl2index = {}
self._identical = identical self._identical = identical
if identical: self._fullhndl = self._index2hndl if identical else fullhndllist
self._fullhndl = self._index2hndl
else:
self._fullhndl = fullhndllist
self._reverse = reverse self._reverse = reverse
self.reverse_order() self.reverse_order()
@ -183,9 +180,8 @@ class FlatNodeMap(object):
else: else:
self.__corr = (0, 1) self.__corr = (0, 1)
if not self._hndl2index: if not self._hndl2index:
for index, key in enumerate(self._index2hndl): self._hndl2index = dict([key[1], index]
#the handle is key[1] for index, key in enumerate(self._index2hndl))
self._hndl2index[key[1]] = index
def real_path(self, index): def real_path(self, index):
""" """
@ -222,10 +218,7 @@ class FlatNodeMap(object):
:Returns: the path, or None if handle does not link to a path :Returns: the path, or None if handle does not link to a path
""" """
index = self._hndl2index.get(handle) index = self._hndl2index.get(handle)
if index is None: return None if index is None else self.real_path(index)
return None
else:
return self.real_path(index)
def get_sortkey(self, handle): def get_sortkey(self, handle):
""" """
@ -237,10 +230,7 @@ class FlatNodeMap(object):
:Returns: the sortkey, or None if handle is not present :Returns: the sortkey, or None if handle is not present
""" """
index = self._hndl2index.get(handle) index = self._hndl2index.get(handle)
if index is None: return None if index is None else self._index2hndl[index][0]
return None
else:
return self._index2hndl[index][0]
def get_handle(self, path): def get_handle(self, path):
""" """
@ -528,8 +518,8 @@ class FlatBaseModel(gtk.GenericTreeModel):
if not allkeys: if not allkeys:
allkeys = self.sort_keys() allkeys = self.sort_keys()
if self.search and self.search.text: if self.search and self.search.text:
dlist = [h for h in allkeys \ dlist = [h for h in allkeys
if self.search.match(h[1], self.db) and \ if self.search.match(h[1], self.db) and
h[1] not in self.skip and h[1] != ignore] h[1] not in self.skip and h[1] != ignore]
ident = False ident = False
elif ignore is None and not self.skip: elif ignore is None and not self.skip:
@ -538,7 +528,7 @@ class FlatBaseModel(gtk.GenericTreeModel):
dlist = allkeys dlist = allkeys
else: else:
ident = False ident = False
dlist = [h for h in allkeys \ dlist = [h for h in allkeys
if h[1] not in self.skip and h[1] != ignore] if h[1] not in self.skip and h[1] != ignore]
self.node_map.set_path_map(dlist, allkeys, identical=ident, self.node_map.set_path_map(dlist, allkeys, identical=ident,
reverse=self._reverse) reverse=self._reverse)

View File

@ -144,21 +144,7 @@ class PeopleModel(TreeBaseModel):
self.column_tooltip, self.column_tooltip,
self.column_int_id, self.column_int_id,
] ]
self.hmap = [ self.hmap = [self.column_header] + [None]*len(self.smap)
self.column_header,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
]
TreeBaseModel.__init__(self, db, search=search, skip=skip, TreeBaseModel.__init__(self, db, search=search, skip=skip,
tooltip_column=11, marker_column=10, tooltip_column=11, marker_column=10,
scol=scol, order=order, sort_map=sort_map) scol=scol, order=order, sort_map=sort_map)

View File

@ -64,21 +64,7 @@ class PlaceTreeModel(PlaceBaseModel, TreeBaseModel):
def __init__(self, db, scol=0, order=gtk.SORT_ASCENDING, search=None, def __init__(self, db, scol=0, order=gtk.SORT_ASCENDING, search=None,
skip=set(), sort_map=None): skip=set(), sort_map=None):
self.hmap = [ self.hmap = [self.column_header] + [None]*12
self.column_header,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
]
PlaceBaseModel.__init__(self, db) PlaceBaseModel.__init__(self, db)
TreeBaseModel.__init__(self, db, scol=scol, order=order, TreeBaseModel.__init__(self, db, scol=scol, order=order,

View File

@ -403,11 +403,9 @@ class TreeBaseModel(gtk.GenericTreeModel):
path = self.on_get_path(node) path = self.on_get_path(node)
parent = self.tree[node][0] parent = self.tree[node][0]
del self.tree[node] del self.tree[node]
new_list = [] new_list = [child for child in self.children[parent]
for child in self.children[parent]: if child[1] != node]
if child[1] != node: if not new_list:
new_list.append(child)
if len(new_list) == 0:
del self.children[parent] del self.children[parent]
else: else:
self.children[parent] = new_list self.children[parent] = new_list