Optimise algorithm by reducing number of invocations

This commit is contained in:
Kristóf Tóth 2018-09-02 16:47:52 +02:00
parent a47777ce23
commit cac52effa8
1 changed files with 8 additions and 8 deletions

View File

@ -29,16 +29,16 @@ class Normalisename:
def whitelist(self): def whitelist(self):
return self._whitelist.union({self.separator}) return self._whitelist.union({self.separator})
def __call__(self, files): def __call__(self, paths):
for path in files: for path in paths:
if not self.check_normal(path): directory = dirname(path)
directory = dirname(path) filename = basename(path)
filename = basename(path) normalpath = joinpath(directory, self.normalname(filename))
normalpath = joinpath(directory, self.normalname(filename)) if path != normalpath:
self.operation(path, normalpath) # pylint: disable=not-callable self.operation(path, normalpath) # pylint: disable=not-callable
def check_normal(self, filename): def check_normal(self, path):
filename = basename(filename) filename = basename(path)
return filename == self.normalname(filename) return filename == self.normalname(filename)
def normalname(self, filename): def normalname(self, filename):