Author: Alex Gaynor <[email protected]>
Branch: 
Changeset: r61033:96802b7f8b62
Date: 2013-02-10 01:55 -0800
http://bitbucket.org/pypy/pypy/changeset/96802b7f8b62/

Log:    Constant fold str.{start,end}swith in the annotator

diff --git a/rpython/annotator/test/test_annrpython.py 
b/rpython/annotator/test/test_annrpython.py
--- a/rpython/annotator/test/test_annrpython.py
+++ b/rpython/annotator/test/test_annrpython.py
@@ -3915,8 +3915,16 @@
                                             int, int]),
                           annmodel.SomeInteger)
 
+    def test_constant_startswith_endswith(self):
+        def f():
+            return "abc".startswith("ab") and "abc".endswith("bc")
+        a = self.RPythonAnnotator()
+        assert a.build_types(f, []).const is True
+
+
 def g(n):
-    return [0,1,2,n]
+    return [0, 1, 2, n]
+
 
 def f_calls_g(n):
     total = 0
@@ -3932,4 +3940,3 @@
 class Freezing:
     def _freeze_(self):
         return True
-
diff --git a/rpython/annotator/unaryop.py b/rpython/annotator/unaryop.py
--- a/rpython/annotator/unaryop.py
+++ b/rpython/annotator/unaryop.py
@@ -456,9 +456,13 @@
                  SomeUnicodeString):
 
     def method_startswith(str, frag):
+        if str.is_constant() and frag.is_constant():
+            return immutablevalue(str.const.startswith(frag.const))
         return s_Bool
 
     def method_endswith(str, frag):
+        if str.is_constant() and frag.is_constant():
+            return immutablevalue(str.const.endswith(frag.const))
         return s_Bool
 
     def method_find(str, frag, start=None, end=None):
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to