From 84c1ad65fc1bc2a43b446f4e5fe84e9e21f87001 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Fri, 8 May 2015 16:25:38 -0700 Subject: [PATCH] Avoid creating temporary removal lists Instead of creating a temporary list, only to then iterate over it (and then never again use that temporary list) just use itertools and create an iterator that we use for iterating (therefore avoiding any need to create a temporary list). Part of ongoing blueprint make-things-speedy Change-Id: I5322e5bdf613d485fbc8851c1319a907b425e2dd --- taskflow/persistence/backends/impl_memory.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/taskflow/persistence/backends/impl_memory.py b/taskflow/persistence/backends/impl_memory.py index 31913a6b..ab3bf25c 100644 --- a/taskflow/persistence/backends/impl_memory.py +++ b/taskflow/persistence/backends/impl_memory.py @@ -17,6 +17,7 @@ import contextlib import copy +import itertools import posixpath as pp import six @@ -196,9 +197,8 @@ class FakeFilesystem(object): node = self._fetch_node(path, normalized=True) if node is self._root: raise ValueError("Can not delete '%s'" % self._root.item) - removals = [path] - removals.extend(child.metadata['path'] for child in node.bfs_iter()) - for path in removals: + child_gen = (child.metadata['path'] for child in node.bfs_iter()) + for path in itertools.chain([path], child_gen): self._reverse_mapping.pop(path, None) node.disassociate()