Commit fd11571a authored by Stefan Behnel's avatar Stefan Behnel

simplify some builtin method optimisations

parent a69b00fd
......@@ -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"),
......
......@@ -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),
......
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()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment