From 19a5facae54a2448cb4765f465ec9702687bfdff Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Thu, 28 Jan 2016 00:02:33 +0200 Subject: [PATCH] generic: add usefull scripts Signed-off-by: Ivailo Monev --- inlinecheck.py | 22 ++++++++++++++++++++++ qstringarg.py | 24 ++++++++++++++++++++++++ qstringlistopti.py | 19 +++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100755 inlinecheck.py create mode 100755 qstringarg.py create mode 100755 qstringlistopti.py diff --git a/inlinecheck.py b/inlinecheck.py new file mode 100755 index 0000000..532aff1 --- /dev/null +++ b/inlinecheck.py @@ -0,0 +1,22 @@ +#!/usr/bin/python2 + +# a script to check for possible functions inlining/deinlining in headers files + +import os, re + +regex = re.compile('(.*[\\t| ](.*)\(\).*\{.*return.*\(\).*\})') + +for root, dirs, files in os.walk(os.getcwd()): + for sfile in files: + if not sfile.endswith(('.hpp', '.h', '.hh')): + continue + sfull = '%s/%s' % (root, sfile) + with open(sfull, 'rb') as f: + content = f.read() + for match in regex.findall(content): + if 'inline' in match[0]: + print('possible removal of %s in %s' % (match[1], sfull.replace('%s/' % os.getcwd(), ""))) + continue + elif 'const' in match[0] or 'virtual' in match[0]: + continue + print('possible inlining of %s in %s' % (match[1], sfull.replace('%s/' % os.getcwd(), ""))) diff --git a/qstringarg.py b/qstringarg.py new file mode 100755 index 0000000..4848304 --- /dev/null +++ b/qstringarg.py @@ -0,0 +1,24 @@ +#!/usr/bin/python2 + +# a script to check for possible optimization of QString formatter + +# if you are going to apply changes make sure you do not mix types, +# the method has several overloads! + +import os, re + +regex = re.compile('\.arg\(') + +for root, ldirs, lfiles in os.walk(os.getcwd()): + for sfile in lfiles: + sfull = '%s/%s' % (root, sfile) + if '/.git/' in sfull: + continue + printfile = False + with open(sfull, 'r') as f: + for sline in f.readlines(): + if len(regex.findall(sline)) > 1: + printfile = True + break + if printfile: + print(sfull) diff --git a/qstringlistopti.py b/qstringlistopti.py new file mode 100755 index 0000000..4a09da7 --- /dev/null +++ b/qstringlistopti.py @@ -0,0 +1,19 @@ +#!/usr/bin/python2 + +# a script to check for possible optimization of QStringList usage + +import os, re + +regex = re.compile('QStringList (.[^\\s|;|(]+)') + +for root, dirs, files in os.walk(os.getcwd()): + for sfile in files: + if not sfile.endswith(('.hpp', '.h', '.hh', '.cpp', '.c', 'cc')): + continue + sfull = '%s/%s' % (root, sfile) + with open(sfull, 'rb') as f: + content = f.read() + for match in regex.findall(content): + if ('%s.append(' % match in content or '%s.prepend(' % match in content) \ + and not '%s.reserve(' % match in content: + print('possible optimzation of %s in %s' % (match, sfull.replace('%s/' % os.getcwd(), "")))