summaryrefslogtreecommitdiff
path: root/GstDebugViewer
diff options
context:
space:
mode:
authorRené Stadler <mail@renestadler.de>2012-09-21 22:15:07 +0200
committerRené Stadler <mail@renestadler.de>2012-09-21 22:15:07 +0200
commit481e0932407725ca842badd65a04df32db5eb490 (patch)
tree7fa938ef2089689ff4b6fa8e468755350a128647 /GstDebugViewer
parentfcf2a36abe1ba2488e3390a3b0e821a6e4a1107b (diff)
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.
Diffstat (limited to 'GstDebugViewer')
-rw-r--r--GstDebugViewer/Data.py24
1 files changed, 17 insertions, 7 deletions
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