Author: Tyler Wade <[email protected]>
Branch: utf8-unicode2
Changeset: r73347:7b8e8bfabdc3
Date: 2014-08-17 01:21 -0500
http://bitbucket.org/pypy/pypy/changeset/7b8e8bfabdc3/

Log:    Give app-level unicode objects a specialized iterator

diff --git a/pypy/objspace/std/iterobject.py b/pypy/objspace/std/iterobject.py
--- a/pypy/objspace/std/iterobject.py
+++ b/pypy/objspace/std/iterobject.py
@@ -113,6 +113,19 @@
         self.index = index + 1
         return w_item
 
+class W_FastUnicodeIterObject(W_AbstractSeqIterObject):
+    def __init__(self, w_uni, index=0):
+        W_AbstractSeqIterObject.__init__(self, w_uni, index)
+        self.iter = iter(w_uni._value)
+
+    def descr_next(self, space):
+        try:
+            next = self.iter.next()
+        except StopIteration:
+            raise OperationError(space.w_StopIteration, space.w_None)
+        self.index += 1
+        return space.wrap(next)
+
 
 class W_ReverseSeqIterObject(W_Root):
     def __init__(self, space, w_seq, index=-1):
diff --git a/pypy/objspace/std/objspace.py b/pypy/objspace/std/objspace.py
--- a/pypy/objspace/std/objspace.py
+++ b/pypy/objspace/std/objspace.py
@@ -22,7 +22,7 @@
 from pypy.objspace.std.dictmultiobject import W_DictMultiObject
 from pypy.objspace.std.floatobject import W_FloatObject
 from pypy.objspace.std.intobject import W_IntObject
-from pypy.objspace.std.iterobject import W_AbstractSeqIterObject
+from pypy.objspace.std.iterobject import W_AbstractSeqIterObject, 
W_FastUnicodeIterObject
 from pypy.objspace.std.listobject import W_ListObject
 from pypy.objspace.std.longobject import W_LongObject, newlong
 from pypy.objspace.std.bufferobject import W_Buffer
@@ -317,6 +317,8 @@
         return W_SliceObject(w_start, w_end, w_step)
 
     def newseqiter(self, w_obj):
+        if isinstance(w_obj, W_UnicodeObject):
+            return W_FastUnicodeIterObject(w_obj)
         return W_SeqIterObject(w_obj)
 
     def newbuffer(self, w_obj):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to