simplify some builtin method optimisations
authorStefan Behnel <scoder@users.berlios.de>
Sun, 7 Nov 2010 09:24:21 +0000 (10:24 +0100)
committerStefan Behnel <scoder@users.berlios.de>
Sun, 7 Nov 2010 09:24:21 +0000 (10:24 +0100)
Cython/Compiler/Builtin.py
Cython/Compiler/Optimize.py
tests/run/list.pyx

index fbed2e3175cbc05078b07248516a177a2baf6026..7b20b756904854824fe28275117527e9fd2b0b5b 100644 (file)
@@ -112,7 +112,10 @@ builtin_types_table = [
 
     ("tuple",   "PyTuple_Type",    []),
 
-    ("list",    "PyList_Type",     [("insert", "TzO",  "i", "PyList_Insert")]),
+    ("list",    "PyList_Type",     [("insert",  "TzO",  "i", "PyList_Insert"),
+                                    ("reverse", "T",    "i", "PyList_Reverse"),
+                                    ("append",  "TO",   "i", "PyList_Append"),
+                                    ]),
 
     ("dict",    "PyDict_Type",     [("items", "T",   "O", "PyDict_Items"),
                                     ("keys",  "T",   "O", "PyDict_Keys"),
index f70a68e3eda58b335c28e9c40699fefcd4bc59be..a54c916ed986d3ca721f5346b86cc3af9e36d804 100644 (file)
@@ -2063,23 +2063,6 @@ class OptimizeBuiltinCalls(Visitor.EnvTransform):
 
     _handle_simple_method_list_pop = _handle_simple_method_object_pop
 
-    PyList_Append_func_type = PyrexTypes.CFuncType(
-        PyrexTypes.c_int_type, [
-            PyrexTypes.CFuncTypeArg("list", PyrexTypes.py_object_type, None),
-            PyrexTypes.CFuncTypeArg("item", PyrexTypes.py_object_type, None),
-            ],
-        exception_value = "-1")
-
-    def _handle_simple_method_list_append(self, node, args, is_unbound_method):
-        """Call PyList_Append() instead of l.append().
-        """
-        if len(args) != 2:
-            self._error_wrong_arg_count('list.append', node, args, 2)
-            return node
-        return self._substitute_method_call(
-            node, "PyList_Append", self.PyList_Append_func_type,
-            'append', is_unbound_method, args)
-
     single_param_func_type = PyrexTypes.CFuncType(
         PyrexTypes.c_int_type, [
             PyrexTypes.CFuncTypeArg("obj", PyrexTypes.py_object_type, None),
@@ -2095,16 +2078,6 @@ class OptimizeBuiltinCalls(Visitor.EnvTransform):
             node, "PyList_Sort", self.single_param_func_type,
             'sort', is_unbound_method, args)
 
-    def _handle_simple_method_list_reverse(self, node, args, is_unbound_method):
-        """Call PyList_Reverse() instead of l.reverse().
-        """
-        if len(args) != 1:
-            self._error_wrong_arg_count('list.reverse', node, args, 1)
-            return node
-        return self._substitute_method_call(
-            node, "PyList_Reverse", self.single_param_func_type,
-            'reverse', is_unbound_method, args)
-
     Pyx_PyDict_GetItem_func_type = PyrexTypes.CFuncType(
         PyrexTypes.py_object_type, [
             PyrexTypes.CFuncTypeArg("dict", PyrexTypes.py_object_type, None),
index 9b1fec2456d30d6d1843c1f9bc09d7332b2da60f..f4fc0d3c73150e81dd3d54c2f559fefbabf5ffb9 100644 (file)
@@ -1,3 +1,6 @@
+
+cimport cython
+
 def f(obj1, obj2, obj3, obj4, obj5):
     """
     >>> f(1, 2, 3, 4, 5)
@@ -54,6 +57,7 @@ def test_list_sort_reversed():
     l1.sort(reversed=True)
     return l1
 
+@cython.test_assert_path_exists("//SimpleCallNode//NoneCheckNode")
 def test_list_reverse():
     """
     >>> test_list_reverse()
@@ -64,6 +68,17 @@ def test_list_reverse():
     l1.reverse()
     return l1
 
+@cython.test_assert_path_exists("//SimpleCallNode//NoneCheckNode")
+def test_list_append():
+    """
+    >>> test_list_append()
+    [1, 2, 3, 4]
+    """
+    cdef list l1 = [1,2]
+    l1.append(3)
+    l1.append(4)
+    return l1
+
 def test_list_pop():
     """
     >>> test_list_pop()