simplify iter() optimisation based on signature override
authorStefan Behnel <scoder@users.berlios.de>
Wed, 3 Nov 2010 19:35:38 +0000 (20:35 +0100)
committerStefan Behnel <scoder@users.berlios.de>
Wed, 3 Nov 2010 19:35:38 +0000 (20:35 +0100)
Cython/Compiler/Builtin.py
Cython/Compiler/Optimize.py

index f7b598066401f65e48b5befde44d2ce0198d7ed8..507bfb4692a0b2e31a75ef6fc79e52253cc33431 100644 (file)
@@ -33,6 +33,8 @@ builtin_function_table = [
     ('isinstance', "OO",   "b",     "PyObject_IsInstance"),
     ('issubclass', "OO",   "b",     "PyObject_IsSubclass"),
     #('iter',       "O",    "O",     "PyObject_GetIter"),   # optimised later on
+    ('iter',       "OO",   "O",     "PyCallIter_New"),
+    ('iter',       "O",    "O",     "PyObject_GetIter"),
     ('len',        "O",    "z",     "PyObject_Length"),
     ('locals',     "",     "O",     "__pyx_locals"),
     #('map',       "",     "",      ""),
index bc0d4b3c131719c5457616fe0b08576db7d5e98d..04f741f3b46a8ce15f00bc2d4aae1b39a5ec2a88 100644 (file)
@@ -1852,35 +1852,6 @@ class OptimizeBuiltinCalls(Visitor.EnvTransform):
             self._error_wrong_arg_count('getattr', node, pos_args, '2 or 3')
         return node
 
-    PyObject_GetIter_func_type = PyrexTypes.CFuncType(
-        PyrexTypes.py_object_type, [
-            PyrexTypes.CFuncTypeArg("object", PyrexTypes.py_object_type, None),
-            ])
-
-    PyCallIter_New_func_type = PyrexTypes.CFuncType(
-        PyrexTypes.py_object_type, [
-            PyrexTypes.CFuncTypeArg("object", PyrexTypes.py_object_type, None),
-            PyrexTypes.CFuncTypeArg("sentinel", PyrexTypes.py_object_type, None),
-            ])
-
-    def _handle_simple_function_iter(self, node, pos_args):
-        """Replace 1/2 argument forms of iter() by C-API calls.
-        """
-        if len(pos_args) == 1:
-            return ExprNodes.PythonCapiCallNode(
-                node.pos, "PyObject_GetIter", self.PyObject_GetIter_func_type,
-                args = pos_args,
-                may_return_none = True,
-                is_temp = node.is_temp)
-        elif len(pos_args) == 2:
-            return ExprNodes.PythonCapiCallNode(
-                node.pos, "PyCallIter_New", self.PyCallIter_New_func_type,
-                args = pos_args,
-                is_temp = node.is_temp)
-        else:
-            self._error_wrong_arg_count('iter', node, pos_args, '1 or 2')
-        return node
-
     Pyx_strlen_func_type = PyrexTypes.CFuncType(
         PyrexTypes.c_size_t_type, [
             PyrexTypes.CFuncTypeArg("bytes", PyrexTypes.c_char_ptr_type, None)