[pypy-commit] pypy unicode-utf8: use iterator for islower

fijal pypy.commits at gmail.com
Wed Dec 6 11:48:25 EST 2017


Author: fijal
Branch: unicode-utf8
Changeset: r93286:55238fb1d18a
Date: 2017-12-06 18:47 +0200
http://bitbucket.org/pypy/pypy/changeset/55238fb1d18a/

Log:	use iterator for islower

diff --git a/pypy/objspace/std/test/test_liststrategies.py b/pypy/objspace/std/test/test_liststrategies.py
--- a/pypy/objspace/std/test/test_liststrategies.py
+++ b/pypy/objspace/std/test/test_liststrategies.py
@@ -7,6 +7,7 @@
     IntOrFloatListStrategy)
 from pypy.objspace.std import listobject
 from pypy.objspace.std.test.test_listobject import TestW_ListObject
+from rpython.rlib.rutf8 import FLAG_ASCII
 
 
 class TestW_ListStrategies(TestW_ListObject):
@@ -600,9 +601,9 @@
     def test_unicode(self):
         l1 = W_ListObject(self.space, [self.space.newbytes("eins"), self.space.newbytes("zwei")])
         assert isinstance(l1.strategy, BytesListStrategy)
-        l2 = W_ListObject(self.space, [self.space.newutf8("eins", 4, 2), self.space.newutf8("zwei", 4, 2)])
+        l2 = W_ListObject(self.space, [self.space.newutf8("eins", 4, FLAG_ASCII), self.space.newutf8("zwei", 4, FLAG_ASCII)])
         assert isinstance(l2.strategy, UnicodeListStrategy)
-        l3 = W_ListObject(self.space, [self.space.newbytes("eins"), self.space.newutf8("zwei", 4, 2)])
+        l3 = W_ListObject(self.space, [self.space.newbytes("eins"), self.space.newutf8("zwei", 4, FLAG_ASCII)])
         assert isinstance(l3.strategy, ObjectListStrategy)
 
     def test_listview_bytes(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
@@ -524,16 +524,12 @@
 
     def descr_islower(self, space):
         cased = False
-        val = self._utf8
-        i = 0
-        while i < len(val):
-            uchar = rutf8.codepoint_at_pos(val, i)
+        for uchar in rutf8.Utf8StringIterator(self._utf8):
             if (unicodedb.isupper(uchar) or
                 unicodedb.istitle(uchar)):
                 return space.w_False
             if not cased and unicodedb.islower(uchar):
                 cased = True
-            i = rutf8.next_codepoint_pos(val, i)
         return space.newbool(cased)
 
     def descr_istitle(self, space):


More information about the pypy-commit mailing list