Author: Carl Friedrich Bolz-Tereick <cfb...@gmx.de>
Branch: 
Changeset: r97487:6e05da20e7bd
Date: 2019-09-16 10:51 +0200
http://bitbucket.org/pypy/pypy/changeset/6e05da20e7bd/

Log:    call prev_codepoint_pos only once

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
@@ -1085,9 +1085,11 @@
                 lgt -= 1
 
         if right:
-            while rpos > lpos and rutf8.isspace(value,
-                                         rutf8.prev_codepoint_pos(value, 
rpos)):
-                rpos = rutf8.prev_codepoint_pos(value, rpos)
+            while rpos > lpos:
+                prev = rutf8.prev_codepoint_pos(value, rpos)
+                if not rutf8.isspace(value, prev):
+                    break
+                rpos = prev
                 lgt -= 1
 
         assert rpos >= lpos    # annotator hint, don't remove
@@ -1108,9 +1110,11 @@
                 lgt -= 1
 
         if right:
-            while rpos > lpos and rutf8.utf8_in_chars(value,
-                    rutf8.prev_codepoint_pos(value, rpos), chars):
-                rpos = rutf8.prev_codepoint_pos(value, rpos)
+            while rpos > lpos:
+                prev = rutf8.prev_codepoint_pos(value, rpos)
+                if not rutf8.utf8_in_chars(value, prev, chars):
+                    break
+                rpos = prev
                 lgt -= 1
 
         assert rpos >= lpos    # annotator hint, don't remove
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to