[pypy-commit] pypy default: Don't allocate a small list here

arigo pypy.commits at gmail.com
Wed Oct 30 05:32:23 EDT 2019


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r97890:195ceabd426e
Date: 2019-10-30 10:31 +0100
http://bitbucket.org/pypy/pypy/changeset/195ceabd426e/

Log:	Don't allocate a small list here

diff --git a/pypy/interpreter/unicodehelper.py b/pypy/interpreter/unicodehelper.py
--- a/pypy/interpreter/unicodehelper.py
+++ b/pypy/interpreter/unicodehelper.py
@@ -1184,9 +1184,9 @@
     size = len(s)
 
     if BYTEORDER == 'little':
-        iorder = [0, 1, 2, 3]
+        iorder0, iorder1, iorder2, iorder3 = 0, 1, 2, 3
     else:
-        iorder = [3, 2, 1, 0]
+        iorder0, iorder1, iorder2, iorder3 = 3, 2, 1, 0
 
     #  Check for BOM marks (U+FEFF) in the input and adjust current
     #  byte order setting accordingly. In native mode, the leading BOM
@@ -1196,8 +1196,8 @@
     if byteorder == 'native':
         if size >= 4:
             bom = intmask(
-                (ord(s[iorder[3]]) << 24) | (ord(s[iorder[2]]) << 16) |
-                (ord(s[iorder[1]]) << 8) | ord(s[iorder[0]]))
+                (ord(s[iorder3]) << 24) | (ord(s[iorder2]) << 16) |
+                (ord(s[iorder1]) << 8) | ord(s[iorder0]))
             if BYTEORDER == 'little':
                 if bom == BOM32_DIRECT:
                     pos += 4
@@ -1220,10 +1220,10 @@
         return '', 0, 0, bo
     if bo == -1:
         # force little endian
-        iorder = [0, 1, 2, 3]
+        iorder0, iorder1, iorder2, iorder3 = 0, 1, 2, 3
     elif bo == 1:
         # force big endian
-        iorder = [3, 2, 1, 0]
+        iorder0, iorder1, iorder2, iorder3 = 3, 2, 1, 0
 
     result = StringBuilder(size // 4)
 
@@ -1239,8 +1239,8 @@
             if len(s) - pos < 4:
                 break
             continue
-        ch = ((ord(s[pos + iorder[3]]) << 24) | (ord(s[pos + iorder[2]]) << 16) |
-              (ord(s[pos + iorder[1]]) << 8)  | ord(s[pos + iorder[0]]))
+        ch = ((ord(s[pos + iorder3]) << 24) | (ord(s[pos + iorder2]) << 16) |
+              (ord(s[pos + iorder1]) << 8)  | ord(s[pos + iorder0]))
         if not allow_surrogates and 0xD800 <= ch <= 0xDFFF:
             r, pos = errorhandler(errors, public_encoding_name,
                                   "code point in surrogate code point "


More information about the pypy-commit mailing list