Data: improve stripped log file loading performance

A ~9% improvement for files without colors. This now slightly outperforms the
code before color support was added.
This commit is contained in:
René Stadler 2012-09-21 22:15:07 +02:00 committed by Stefan Sauer
parent 6061f34506
commit 103700a254

View file

@ -294,10 +294,14 @@ class LineCache (Producer):
"I" : debug_level_info, "W" : debug_level_warning,
"E" : debug_level_error, " " : debug_level_none}
ANSI = "(?:\x1b\\[[0-9;]*m)?"
rexp = re.compile (r"\d:\d\d:\d\d\.\d+ " + ANSI +
r" *\d+" + ANSI +
r" +0x[0-9a-f]+ +" + ANSI +
r"([TFLDIEW ])")
ANSI_PATTERN = (r"\d:\d\d:\d\d\.\d+ " + ANSI +
r" *\d+" + ANSI +
r" +0x[0-9a-f]+ +" + ANSI +
r"([TFLDIEW ])")
BARE_PATTERN = ANSI_PATTERN.replace (ANSI, "")
rexp_bare = re.compile (BARE_PATTERN)
rexp_ansi = re.compile (ANSI_PATTERN)
rexp = rexp_bare
# Moving attribute lookups out of the loop:
readline = self.__fileobj.readline
@ -323,11 +327,17 @@ class LineCache (Producer):
line = readline ()
if not line:
break
# if line[18] == "\x1b":
# line = strip_escape (line)
match = rexp_match (line)
if match is None:
continue
if rexp is rexp_ansi or not "\x1b" in line:
continue
match = rexp_ansi.match (line)
if match is None:
continue
# Switch to slower ANSI parsing:
rexp = rexp_ansi
rexp_match = rexp.match
# Timestamp is in the very beginning of the row, and can be sorted
# by lexical comparison. That's why we don't bother parsing the