Donate CPU: Optimize `list` and `dict` initialization

Initialization with `[]` and `{}` is faster than with `list()` and `dict()`.
Details:
https://stackoverflow.com/questions/30216000/why-is-faster-than-list
This commit is contained in:
versat 2019-02-12 09:47:57 +01:00
parent 9dc5dbe1ab
commit a41e663cd1
2 changed files with 6 additions and 6 deletions

View File

@ -504,7 +504,7 @@ def check_library_report(result_path, message_id):
'Function' 'Function'
html += '</b>\n' html += '</b>\n'
function_counts = dict() function_counts = {}
for filename in glob.glob(result_path + '/*'): for filename in glob.glob(result_path + '/*'):
if not os.path.isfile(filename): if not os.path.isfile(filename):
continue continue
@ -521,7 +521,7 @@ def check_library_report(result_path, message_id):
function_name = line[(line.find(': Function ') + len(': Function ')):line.rfind('should have') - 1] function_name = line[(line.find(': Function ') + len(': Function ')):line.rfind('should have') - 1]
function_counts[function_name] = function_counts.setdefault(function_name, 0) + 1 function_counts[function_name] = function_counts.setdefault(function_name, 0) + 1
function_details_list = list() function_details_list = []
for function_name, count in sorted(function_counts.iteritems(), key=lambda (k, v): (v, k), reverse=True): for function_name, count in sorted(function_counts.iteritems(), key=lambda (k, v): (v, k), reverse=True):
if len(function_details_list) >= functions_shown_max: if len(function_details_list) >= functions_shown_max:
break break
@ -539,7 +539,7 @@ def check_library_report(result_path, message_id):
def check_library_function_name(result_path, function_name): def check_library_function_name(result_path, function_name):
print('check_library_function_name') print('check_library_function_name')
function_name = urllib.unquote_plus(function_name) function_name = urllib.unquote_plus(function_name)
output_lines_list = list() output_lines_list = []
for filename in glob.glob(result_path + '/*'): for filename in glob.glob(result_path + '/*'):
if not os.path.isfile(filename): if not os.path.isfile(filename):
continue continue

View File

@ -37,7 +37,7 @@ import platform
# Version scheme (MAJOR.MINOR.PATCH) should orientate on "Semantic Versioning" https://semver.org/ # Version scheme (MAJOR.MINOR.PATCH) should orientate on "Semantic Versioning" https://semver.org/
# Every change in this script should result in increasing the version number accordingly (exceptions may be cosmetic # Every change in this script should result in increasing the version number accordingly (exceptions may be cosmetic
# changes) # changes)
CLIENT_VERSION = "1.1.2" CLIENT_VERSION = "1.1.3"
def checkRequirements(): def checkRequirements():
@ -266,8 +266,8 @@ def scanPackage(workPath, cppcheckPath, jobs, fast):
print('Crash!') print('Crash!')
return -1, '', '', -1, options return -1, '', '', -1, options
elapsedTime = stopTime - startTime elapsedTime = stopTime - startTime
information_messages_list = list() information_messages_list = []
issue_messages_list = list() issue_messages_list = []
count = 0 count = 0
for line in stderr.split('\n'): for line in stderr.split('\n'):
if ': information: ' in line: if ': information: ' in line: