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

View File

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

View File

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