[Jython-checkins] jython: Missing file from 7311:946090532a2c

jim.baker jython-checkins at python.org
Sun Jun 22 21:12:33 CEST 2014


http://hg.python.org/jython/rev/257b274ad39e
changeset:   7312:257b274ad39e
user:        Jim Baker <jim.baker at rackspace.com>
date:        Sun Jun 22 13:12:24 2014 -0600
summary:
  Missing file from 7311:946090532a2c

files:
  src/org/python/core/PyXRangeIter.java |  45 +++++++++++++++
  1 files changed, 45 insertions(+), 0 deletions(-)


diff --git a/src/org/python/core/PyXRangeIter.java b/src/org/python/core/PyXRangeIter.java
new file mode 100644
--- /dev/null
+++ b/src/org/python/core/PyXRangeIter.java
@@ -0,0 +1,45 @@
+/* Copyright (c) Jython Developers */
+package org.python.core;
+
+import org.python.expose.ExposedMethod;
+import org.python.expose.ExposedType;
+
+/**
+ * Specially optimized xrange iterator.
+ */
+ at ExposedType(name = "rangeiterator", base = PyObject.class, isBaseType = false)
+public class PyXRangeIter extends PyIterator {
+
+    public static final PyType TYPE = PyType.fromClass(PyXRangeIter.class);
+    static {
+        TYPE.setName("rangeiterator");
+    }
+
+    private long index;
+    private long start;
+    private long step;
+    private long len;
+
+    public PyXRangeIter(long index, long start, long step, long len) {
+        super(TYPE);
+        this.index = index;
+        this.start = start;
+        this.step = step;
+        this.len = len;
+    }
+
+    @ExposedMethod(doc = "x.next() -> the next value, or raise StopIteration")
+    final PyObject rangeiterator_next() {
+        return super.next();
+    }
+
+    @Override
+    public PyObject __iternext__() {
+        if (index < len) {
+            return Py.newInteger(start + index++ * step);
+        }
+
+        return null;
+    }
+
+}

-- 
Repository URL: http://hg.python.org/jython


More information about the Jython-checkins mailing list