[pypy-svn] r10003 - pypy/dist/pypy/lib

alex at codespeak.net alex at codespeak.net
Mon Mar 21 18:14:04 CET 2005


Author: alex
Date: Mon Mar 21 18:14:03 2005
New Revision: 10003

Modified:
   pypy/dist/pypy/lib/itertools.py
Log:
fixed islice implementation (now simpler)



Modified: pypy/dist/pypy/lib/itertools.py
==============================================================================
--- pypy/dist/pypy/lib/itertools.py	(original)
+++ pypy/dist/pypy/lib/itertools.py	Mon Mar 21 18:14:03 2005
@@ -353,15 +353,20 @@
     report may list a name field on every third line).
     """ 
     s = slice(*args)
-    next, stop, step = s.start or 0, s.stop, s.step or 1
+    start, stop, step = s.start or 0, s.stop, s.step or 1
+    next = iter(iterable).next
     cnt = 0 
-    for element in enumerate(iterable):
-        if cnt < next:
-            continue
-        if stop is not None and cnt >= stop:
-            break
-        yield element
-        next += step
+    while cnt < start:
+        next()
+	cnt += 1
+    while stop is None or cnt < stop:
+        yield next()
+	cnt += 1
+        skip = step - 1
+	while skip:
+	    next()
+	    cnt += 1
+	    skip -= 1
 
 class izip:
     """Make an iterator that aggregates elements from each of the



More information about the Pypy-commit mailing list