`search_file` scans the whole underlying folder structure
When looking into a directory for a file with search_file(base_path, options)
, the whole structure of the base_path
get scanned L395. The time complexity increases linearly with the number of underlying files.
This behavior is fine if the intended design was for options
to be an incomplete relative path within the base_path
. However if it is expected that options
are complete relative path, one can speed up the process as follow:
f = None
for o in options:
try:
f = open(os.path.join(base_path, o)
break
except OSError:
pass # File does not exist
return f
It implements the same behavior, assuming options
is the full relative path, and speed up the search.