[pypy-commit] pypy default: add an ascii fastpath

cfbolz pypy.commits at gmail.com
Thu Sep 12 03:50:28 EDT 2019


Author: Carl Friedrich Bolz-Tereick <cfbolz at gmx.de>
Branch: 
Changeset: r97454:2881d923dbb6
Date: 2019-09-12 09:30 +0200
http://bitbucket.org/pypy/pypy/changeset/2881d923dbb6/

Log:	add an ascii fastpath

diff --git a/pypy/module/_io/interp_textio.py b/pypy/module/_io/interp_textio.py
--- a/pypy/module/_io/interp_textio.py
+++ b/pypy/module/_io/interp_textio.py
@@ -427,8 +427,24 @@
     def find_char(self, marker, limit):
         # only works for ascii markers!
         assert 0 <= ord(marker) < 128
+        # ascii fast path
+        if self.ulen == len(self.text):
+            if limit < 0:
+                end = len(self.text)
+            else:
+                end = self.pos + limit
+            pos = self.text.find(marker, self.pos, end)
+            if pos >= 0:
+                self.pos = self.upos = pos + 1
+                return True
+            else:
+                self.pos = self.upos = end
+                return False
+
         if limit < 0:
             limit = sys.maxint
+        # XXX it might be better to search for the marker quickly, then compute
+        # the new upos afterwards.
         scanned = 0
         while scanned < limit:
             # don't use next_char here, since that computes a slice etc


More information about the pypy-commit mailing list