queue -> stack (#45002)
This commit is contained in:
parent
a6e6093922
commit
5b4edb9499
@ -128,9 +128,9 @@ def startfile_prefix(prefix: str, compatible_with: str = sys.executable) -> Opti
|
||||
except Exception:
|
||||
accept = lambda path: True
|
||||
|
||||
queue = [(0, prefix)]
|
||||
while queue:
|
||||
depth, path = queue.pop()
|
||||
stack = [(0, prefix)]
|
||||
while stack:
|
||||
depth, path = stack.pop()
|
||||
try:
|
||||
iterator = os.scandir(path)
|
||||
except OSError:
|
||||
@ -140,7 +140,7 @@ def startfile_prefix(prefix: str, compatible_with: str = sys.executable) -> Opti
|
||||
try:
|
||||
if entry.is_dir(follow_symlinks=True):
|
||||
if depth < 2:
|
||||
queue.append((depth + 1, entry.path))
|
||||
stack.append((depth + 1, entry.path))
|
||||
elif entry.name == "crt1.o" and accept(entry.path):
|
||||
return path
|
||||
except Exception:
|
||||
|
@ -497,10 +497,10 @@ def anchorify(data: Union[dict, list], identifier: Callable[[Any], str] = repr)
|
||||
"""Replace identical dict/list branches in tree with references to earlier instances. The YAML
|
||||
serializer generate anchors for them, resulting in small yaml files."""
|
||||
anchors: Dict[str, Union[dict, list]] = {}
|
||||
queue: List[Union[dict, list]] = [data]
|
||||
stack: List[Union[dict, list]] = [data]
|
||||
|
||||
while queue:
|
||||
item = queue.pop()
|
||||
while stack:
|
||||
item = stack.pop()
|
||||
|
||||
for key, value in item.items() if isinstance(item, dict) else enumerate(item):
|
||||
if not isinstance(value, (dict, list)):
|
||||
@ -511,7 +511,7 @@ def anchorify(data: Union[dict, list], identifier: Callable[[Any], str] = repr)
|
||||
|
||||
if anchor is None:
|
||||
anchors[id] = value
|
||||
queue.append(value)
|
||||
stack.append(value)
|
||||
else:
|
||||
item[key] = anchor # replace with reference
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user