diff options
author | Carl Friedrich Bolz-Tereick <cfbolz@gmx.de> | 2019-09-16 10:51:38 +0200 |
---|---|---|
committer | Carl Friedrich Bolz-Tereick <cfbolz@gmx.de> | 2019-09-16 10:51:38 +0200 |
commit | c76b5e87b508859cdc955b4f7d991e39c1ae7826 (patch) | |
tree | c40ebfdc6d0f2231bd22abae0aae469d90630b1a | |
parent | for some reason we have two rutf8 functions that do the same thing, (diff) | |
download | pypy-c76b5e87b508859cdc955b4f7d991e39c1ae7826.tar.gz pypy-c76b5e87b508859cdc955b4f7d991e39c1ae7826.tar.bz2 pypy-c76b5e87b508859cdc955b4f7d991e39c1ae7826.zip |
call prev_codepoint_pos only once
-rw-r--r-- | pypy/objspace/std/unicodeobject.py | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/pypy/objspace/std/unicodeobject.py b/pypy/objspace/std/unicodeobject.py index 5aeb42d558..31baf5e2cd 100644 --- a/pypy/objspace/std/unicodeobject.py +++ b/pypy/objspace/std/unicodeobject.py @@ -1085,9 +1085,11 @@ class W_UnicodeObject(W_Root): 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 @@ class W_UnicodeObject(W_Root): 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 |