paths: use set and isdisjoint

Time: 5.36s => 4.85s (before rebase: 4.45s => 3.55s)
This commit is contained in:
Daniel Hahler 2018-10-25 17:34:41 +02:00
parent 6ffa347c77
commit 023e1c78df
2 changed files with 5 additions and 7 deletions

View File

@ -489,7 +489,7 @@ class Session(nodes.FSCollector):
names = self._parsearg(arg) names = self._parsearg(arg)
argpath = names.pop(0).realpath() argpath = names.pop(0).realpath()
paths = [] paths = set()
root = self root = self
# Start with a Session root, and delve to argpath item (dir or file) # Start with a Session root, and delve to argpath item (dir or file)
@ -537,14 +537,12 @@ class Session(nodes.FSCollector):
if dirpath not in seen_dirs: if dirpath not in seen_dirs:
seen_dirs.add(dirpath) seen_dirs.add(dirpath)
pkginit = dirpath.join("__init__.py") pkginit = dirpath.join("__init__.py")
if pkginit.exists() and not any( if pkginit.exists() and parts(pkginit.strpath).isdisjoint(paths):
x in parts(pkginit.strpath) for x in paths
):
for x in root._collectfile(pkginit): for x in root._collectfile(pkginit):
yield x yield x
paths.append(x.fspath.dirpath()) paths.add(x.fspath.dirpath())
if not any(x in parts(path.strpath) for x in paths): if parts(path.strpath).isdisjoint(paths):
for x in root._collectfile(path): for x in root._collectfile(path):
key = (type(x), x.fspath) key = (type(x), x.fspath)
if key in self._node_cache: if key in self._node_cache:

View File

@ -307,4 +307,4 @@ def fnmatch_ex(pattern, path):
def parts(s): def parts(s):
parts = s.split(sep) parts = s.split(sep)
return [sep.join(parts[:i+1]) or sep for i in range(len(parts))] return {sep.join(parts[: i + 1]) or sep for i in range(len(parts))}