From fd11571a4c43139b1bfa2c0ca83cda83a9067549 Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Sun, 7 Nov 2010 10:24:21 +0100 Subject: [PATCH] simplify some builtin method optimisations --- Cython/Compiler/Builtin.py | 5 ++++- Cython/Compiler/Optimize.py | 27 --------------------------- tests/run/list.pyx | 15 +++++++++++++++ 3 files changed, 19 insertions(+), 28 deletions(-) diff --git a/Cython/Compiler/Builtin.py b/Cython/Compiler/Builtin.py index fbed2e31..7b20b756 100644 --- a/Cython/Compiler/Builtin.py +++ b/Cython/Compiler/Builtin.py @@ -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"), diff --git a/Cython/Compiler/Optimize.py b/Cython/Compiler/Optimize.py index f70a68e3..a54c916e 100644 --- a/Cython/Compiler/Optimize.py +++ b/Cython/Compiler/Optimize.py @@ -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), diff --git a/tests/run/list.pyx b/tests/run/list.pyx index 9b1fec24..f4fc0d3c 100644 --- a/tests/run/list.pyx +++ b/tests/run/list.pyx @@ -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() -- 2.26.2