Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f28a204

Browse files
committed
improved performance of item traversal, its nearly as fast as it was with the first very pure implementation
1 parent accfe36 commit f28a204

File tree

1 file changed

+2
-11
lines changed

1 file changed

+2
-11
lines changed

lib/git/objects/utils.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -113,18 +113,15 @@ def traverse( self, predicate = lambda i: True,
113113
``branch_first``
114114
if True, items will be returned branch first, otherwise depth first
115115
116-
``visit_once``
117-
if True, items will only be returned once, although they might be encountered
118-
several times. Loops are prevented that way.
119-
120116
``ignore_self``
121117
if True, self will be ignored and automatically pruned from
122118
the result. Otherwise it will be the first item to be returned"""
123-
visited = set()
124119
stack = Deque()
125120
stack.append( ( 0 ,self ) ) # self is always depth level 0
126121

127122
def addToStack( stack, lst, branch_first, dpth ):
123+
if not lst:
124+
return
128125
if branch_first:
129126
stack.extendleft( ( dpth , item ) for item in lst )
130127
else:
@@ -135,12 +132,6 @@ def addToStack( stack, lst, branch_first, dpth ):
135132
while stack:
136133
d, item = stack.pop() # depth of item, item
137134

138-
if item in visited:
139-
continue
140-
141-
if visit_once:
142-
visited.add( item )
143-
144135
if prune( item ):
145136
continue
146137

0 commit comments

Comments
 (0)