[pypy-commit] pypy unicode-strategies: implement listview_unicode for W_UnicodeObject

antocuni noreply at buildbot.pypy.org
Wed Oct 31 18:06:39 CET 2012


Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: unicode-strategies
Changeset: r58652:09dfbb4ed8dd
Date: 2012-10-31 18:03 +0100
http://bitbucket.org/pypy/pypy/changeset/09dfbb4ed8dd/

Log:	implement listview_unicode for W_UnicodeObject

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
@@ -473,8 +473,8 @@
             return w_obj.listview_unicode()
         if type(w_obj) is W_SetObject or type(w_obj) is W_FrozensetObject:
             return w_obj.listview_unicode()
-        ## if isinstance(w_obj, W_UnicodeObject):
-        ##     return w_obj.listview_unicode()
+        if isinstance(w_obj, W_UnicodeObject):
+            return w_obj.listview_unicode()
         if isinstance(w_obj, W_ListObject) and self._uses_list_iter(w_obj):
             return w_obj.getitems_unicode()
         return None
diff --git a/pypy/objspace/std/test/test_unicodeobject.py b/pypy/objspace/std/test/test_unicodeobject.py
--- a/pypy/objspace/std/test/test_unicodeobject.py
+++ b/pypy/objspace/std/test/test_unicodeobject.py
@@ -23,6 +23,10 @@
         print self.space.config.objspace.std.withrope
         assert len(warnings) == 2
 
+    def test_listview_unicode(self):
+        w_str = self.space.wrap(u'abcd')
+        assert self.space.listview_unicode(w_str) == list(u"abcd")
+
 
 class AppTestUnicodeStringStdOnly:
     def test_compares(self):
diff --git a/pypy/objspace/std/unicodeobject.py b/pypy/objspace/std/unicodeobject.py
--- a/pypy/objspace/std/unicodeobject.py
+++ b/pypy/objspace/std/unicodeobject.py
@@ -66,6 +66,15 @@
     def unicode_w(self, space):
         return self._value
 
+    def listview_unicode(w_self):
+        return _create_list_from_unicode(w_self._value)
+
+def _create_list_from_unicode(value):
+    # need this helper function to allow the jit to look inside and inline
+    # listview_unicode
+    return [s for s in value]
+
+
 W_UnicodeObject.EMPTY = W_UnicodeObject(u'')
 
 registerimplementation(W_UnicodeObject)


More information about the pypy-commit mailing list