# HG changeset patch # User Paul Boddie # Date 1489155652 -3600 # Node ID a0c610ee056232776060d12e6f69f15ab5166e97 # Parent e1c5d2360c5ce9fc16d09f0fb57a03e1a8c05489 Make xrange iteration more efficient by only testing an updated counter when obtaining each new value instead of testing if the value is within the range. diff -r e1c5d2360c5c -r a0c610ee0562 lib/__builtins__/span.py --- a/lib/__builtins__/span.py Thu Mar 09 23:19:43 2017 +0100 +++ b/lib/__builtins__/span.py Fri Mar 10 15:20:52 2017 +0100 @@ -90,7 +90,7 @@ "Initialise the iterator with the given 'obj'." self.start = obj.start - self.end = obj.end + self.count = obj.__len__() self.step = obj.step self.current = obj.start @@ -98,11 +98,12 @@ "Return the next item or raise a StopIteration exception." - if self.step < 0 and self.current <= self.end or self.step > 0 and self.current >= self.end: + if not self.count: raise StopIteration current = self.current self.current += self.step + self.count -= 1 return current def range(start_or_end, end=None, step=1):