# HG changeset patch # User Paul Boddie # Date 1489163218 -3600 # Node ID 85416087aa62d23e139ed11ed8d871eafbb4eeb6 # Parent a0c610ee056232776060d12e6f69f15ab5166e97 Employed specific arithmetic methods for performance when getting new values. Initialise xrangeiterator with only pertinent details, not xrange objects. diff -r a0c610ee0562 -r 85416087aa62 lib/__builtins__/span.py --- a/lib/__builtins__/span.py Fri Mar 10 15:20:52 2017 +0100 +++ b/lib/__builtins__/span.py Fri Mar 10 17:26:58 2017 +0100 @@ -79,20 +79,19 @@ "Return an iterator, currently self." - return xrangeiterator(self) + return xrangeiterator(self.start, self.step, self.__len__()) class xrangeiterator: "An iterator over an xrange." - def __init__(self, obj): + def __init__(self, start, step, count): "Initialise the iterator with the given 'obj'." - self.start = obj.start - self.count = obj.__len__() - self.step = obj.step - self.current = obj.start + self.current = start + self.step = step + self.count = count def next(self): @@ -102,8 +101,8 @@ raise StopIteration current = self.current - self.current += self.step - self.count -= 1 + self.current = self.current.__add__(self.step) + self.count = self.count.__sub__(1) return current def range(start_or_end, end=None, step=1):