Move more attribute lookups out of loops for speed

This commit is contained in:
René Stadler 2008-06-30 19:48:34 +03:00 committed by Stefan Sauer
parent ff146e1cb1
commit 7fdbfa2cf4
2 changed files with 16 additions and 6 deletions

View file

@ -204,8 +204,13 @@ class LineCache (Producer):
"W" : debug_level_warning, " " : debug_level_none}
rexp = re.compile (r"\d:\d\d:\d\d\.\d+\s+\d+\s+0x[0-9a-f]+\s+([DLIEW ])")
# Moving attribute lookups out of the loop:
readline = self.__fileobj.readline
tell = self.__fileobj.tell
rexp_match = rexp.match
levels_append = levels.append
offsets_append = offsets.append
dict_levels_get = dict_levels.get
self.__fileobj.seek (0)
limit = self._lines_per_iteration
@ -215,11 +220,11 @@ class LineCache (Producer):
line = readline ()
if not line:
break
match = rexp.match (line)
match = rexp_match (line)
if match is None:
continue
levels.append (dict_levels.get (match.group (1), debug_level_none))
offsets.append (offset)
levels_append (dict_levels_get (match.group (1), debug_level_none))
offsets_append (offset)
i += 1
if i >= limit:
i = 0

View file

@ -209,10 +209,15 @@ class LogModelBase (gtk.GenericTreeModel):
def iter_rows_offset (self):
ensure_cached = self.ensure_cached
line_cache = self.line_cache
line_levels = self.line_levels
COL_LEVEL = self.COL_LEVEL
for i, offset in enumerate (self.line_offsets):
self.ensure_cached (offset)
row = self.line_cache[offset]
row[self.COL_LEVEL] = self.line_levels[i] # FIXME
ensure_cached (offset)
row = line_cache[offset]
row[COL_LEVEL] = line_levels[i] # FIXME
yield (row, offset,)
def on_get_flags (self):