From d3e4bc91ea330aae76ac36c3930f2e279a45d250 Mon Sep 17 00:00:00 2001 From: Philipp Wolfer Date: Mon, 17 Sep 2018 17:59:36 +0200 Subject: [PATCH] =?UTF-8?q?PICARD-1346:=20Use=20sets=20to=20avoid=20O(n?= =?UTF-8?q?=C2=B2)=20iteration=20when=20moving=20files?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- picard/file.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/picard/file.py b/picard/file.py index b107de954..ae85d8d4a 100644 --- a/picard/file.py +++ b/picard/file.py @@ -427,11 +427,11 @@ class File(QtCore.QObject, Item): old_path = os.path.dirname(old_filename) new_path = os.path.dirname(new_filename) try: - names = os.listdir(old_path) + names = set(os.listdir(old_path)) except os.error: log.error("Error: {} directory not found".naming_format(old_path)) return - filtered_names = [name for name in names if name[0] != "."] + filtered_names = {name for name in names if name[0] != "."} for pattern in config.setting["move_additional_files_pattern"].split(): pattern = pattern.strip() if not pattern: @@ -440,9 +440,10 @@ class File(QtCore.QObject, Item): file_names = names if pattern[0] != '.': file_names = filtered_names - for old_file in file_names: + for old_file in set(file_names): if pattern_regex.match(old_file): - file_names.remove(old_file) + names.discard(old_file) + filtered_names.discard(old_file) new_file = os.path.join(new_path, old_file) old_file = os.path.join(old_path, old_file) # FIXME we shouldn't do this from a thread!