Mikhail Korobov avatar Mikhail Korobov committed b37a582

replace bytearray hack with 'int_from_byte' hack because it is slightly faster under pypy

Comments (0)

Files changed (3)


+import sys
+PY3 = sys.version_info[0] == 3
+if PY3:
+    def int_from_byte(b):
+        return b
+    int_from_byte = ord


 from binascii import a2b_base64
 from . import wrapper
+from .compat import int_from_byte
 class DAWG(object):
         pos = 1
-        for ch in bytearray(key):
-            index = self.dct.follow_char(ch, index)
+        for ch in key:
+            index = self.dct.follow_char(int_from_byte(ch), index)
             if not index:


 import array
 from . import units
+from .compat import int_from_byte
 class Dictionary(object):
     def follow_bytes(self, s, index):
         "Follows transitions."
-        for ch in bytearray(s):
-            index = self.follow_char(ch, index)
+        for ch in s:
+            index = self.follow_char(int_from_byte(ch), index)
             if index is None:
                 return None
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.