From bd6173be6ea531cdf1643910cf4e557235d7a9ba Mon Sep 17 00:00:00 2001 From: Markus Elfring Date: Mon, 7 May 2018 22:18:05 +0200 Subject: [PATCH] Using compiled regular expressions for DACA2 functions (#1209) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ​The method “match” was used as a module-level function in ​for loops of implementations for DACA2 functions so far. Use ​compiled regular expression objects instead. Delete a duplicate element from an alternation. Link: https://trac.cppcheck.net/ticket/8553 Signed-off-by: Markus Elfring --- tools/daca2-report.py | 3 ++- tools/daca2-search.cgi | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/tools/daca2-report.py b/tools/daca2-report.py index 482cdcd63..437793a63 100644 --- a/tools/daca2-report.py +++ b/tools/daca2-report.py @@ -94,6 +94,7 @@ for severity in ['error', 'warning', 'style', 'portability', 'performance']: categories[severity] = [] daca2 = daca2folder +pattern = re.compile(r'.*: (error|warning|style|performance|portability):.* \[([a-zA-Z0-9_\\-]+)\]') for lib in (False, True): for a in "0123456789abcdefghijklmnopqrstuvwxyz": if lib: @@ -120,7 +121,7 @@ for lib in (False, True): datestr = '' for line in data.split('\n'): - res = re.match(r'.*: (error|warning|style|performance|style|portability):.* \[([a-zA-Z0-9_\\-]+)\]', line) + res = pattern.match(line) if res is None: continue severity = res.group(1) diff --git a/tools/daca2-search.cgi b/tools/daca2-search.cgi index dde8452fb..61cafe2e2 100755 --- a/tools/daca2-search.cgi +++ b/tools/daca2-search.cgi @@ -53,10 +53,10 @@ def doSearch(path,arguments): def summary(path, arguments): count = {} + pattern = re.compile(r'.*: (error|warning|style|performance|portability):.*\[([a-zA-Z0-9]+)\]$') for g in getfiles(path, arguments): for line in readlines(g): - line = trimline(line) - res = re.match(r'.*: (error|warning|style|performance|portability):.*\[([a-zA-Z0-9]+)\]$', line) + res = pattern.match(trimline(line)) if res is None: continue id = res.group(2)