mirror of
https://chromium.googlesource.com/chromium/tools/depot_tools.git
synced 2026-01-11 18:51:29 +00:00
metadata: use os.walk to speedup metadata file discovery
os.walk is more efficient than the current handwritten traversal. Measured the time to scan reduced from 30s+ to 8s on p920 on chromium/src. `followlinks=True` is set to preserve behavior that os.path.isdir returns True for symlink to directories, and the current traversal code will descend into those. Change-Id: I941eec9105a46d6538ca484fbb5249a75888e38a Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5379945 Reviewed-by: Anne Redulla <aredulla@google.com> Commit-Queue: Jiewei Qian <qjw@chromium.org>
This commit is contained in:
@@ -28,11 +28,11 @@ def find_metadata_files(root: str) -> List[str]:
|
||||
the root directory.
|
||||
"""
|
||||
metadata_files = []
|
||||
for item in os.listdir(root):
|
||||
full_path = os.path.join(root, item)
|
||||
if is_metadata_file(item):
|
||||
metadata_files.append(full_path)
|
||||
elif os.path.isdir(full_path):
|
||||
metadata_files.extend(find_metadata_files(full_path))
|
||||
|
||||
for (dirpath, _, filenames) in os.walk(root, followlinks=True):
|
||||
for filename in filenames:
|
||||
if is_metadata_file(filename):
|
||||
full_path = os.path.join(root, dirpath, filename)
|
||||
metadata_files.append(full_path)
|
||||
|
||||
return metadata_files
|
||||
|
||||
Reference in New Issue
Block a user