Author: Armin Rigo <[email protected]>
Branch: 
Changeset: r98435:04a0915490aa
Date: 2020-01-01 17:17 +0100
http://bitbucket.org/pypy/pypy/changeset/04a0915490aa/

Log:    Move the 'assert pos >= 0' before the 'code[pos]', to avoid extra
        checking for negative pos when indexing

diff --git a/rpython/rlib/rutf8.py b/rpython/rlib/rutf8.py
--- a/rpython/rlib/rutf8.py
+++ b/rpython/rlib/rutf8.py
@@ -153,22 +153,20 @@
     """Gives the position of the previous codepoint.
     'pos' must not be zero.
     """
-    assert pos != 0
     pos -= 1
+    assert pos >= 0
     if pos >= len(code):     # for the case where pos - 1 == len(code):
-        assert pos >= 0
         return pos           # assume there is an extra '\x00' character
     chr1 = ord(code[pos])
     if chr1 <= 0x7F:
-        assert pos >= 0
         return pos
     pos -= 1
+    assert pos >= 0
     if ord(code[pos]) >= 0xC0:
-        assert pos >= 0
         return pos
     pos -= 1
+    assert pos >= 0
     if ord(code[pos]) >= 0xC0:
-        assert pos >= 0
         return pos
     pos -= 1
     assert pos >= 0
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to