[pypy-commit] pypy default: remove a guard from str.count

cfbolz pypy.commits at gmail.com
Tue Mar 1 07:33:51 EST 2016


Author: Carl Friedrich Bolz <cfbolz at gmx.de>
Branch: 
Changeset: r82632:8d422c65fe9a
Date: 2016-02-27 16:52 +0100
http://bitbucket.org/pypy/pypy/changeset/8d422c65fe9a/

Log:	remove a guard from str.count

diff --git a/rpython/rtyper/lltypesystem/rstr.py b/rpython/rtyper/lltypesystem/rstr.py
--- a/rpython/rtyper/lltypesystem/rstr.py
+++ b/rpython/rtyper/lltypesystem/rstr.py
@@ -717,10 +717,7 @@
             return cls.ll_count_char(s1, s2.chars[0], start, end)
 
         res = cls.ll_search(s1, s2, start, end, FAST_COUNT)
-        # For a few cases ll_search can return -1 to indicate an "impossible"
-        # condition for a string match, count just returns 0 in these cases.
-        if res < 0:
-            res = 0
+        assert res >= 0
         return res
 
     @staticmethod
@@ -741,6 +738,8 @@
         w = n - m
 
         if w < 0:
+            if mode == FAST_COUNT:
+                return 0
             return -1
 
         mlast = m - 1


More information about the pypy-commit mailing list