From 481e0932407725ca842badd65a04df32db5eb490 Mon Sep 17 00:00:00 2001 From: René Stadler Date: Fri, 21 Sep 2012 22:15:07 +0200 Subject: 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. --- GstDebugViewer/Data.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'GstDebugViewer') diff --git a/GstDebugViewer/Data.py b/GstDebugViewer/Data.py index b989a53..2261645 100644 --- a/GstDebugViewer/Data.py +++ b/GstDebugViewer/Data.py @@ -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 -- cgit v1.2.3