From: Stefan Behnel Date: Sun, 21 Mar 2010 07:39:29 +0000 (+0100) Subject: optimise unicode.join() X-Git-Tag: 0.13.beta0~270 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=14e337706f61df74527d6378856b990896ba2912;p=cython.git optimise unicode.join() --- diff --git a/Cython/Compiler/Optimize.py b/Cython/Compiler/Optimize.py index fb2ba8e3..5c6c5ed0 100644 --- a/Cython/Compiler/Optimize.py +++ b/Cython/Compiler/Optimize.py @@ -1444,6 +1444,24 @@ class OptimizeBuiltinCalls(Visitor.EnvTransform): node, "PyUnicode_Splitlines", self.PyUnicode_Splitlines_func_type, 'splitlines', is_unbound_method, args) + PyUnicode_Join_func_type = PyrexTypes.CFuncType( + Builtin.unicode_type, [ + PyrexTypes.CFuncTypeArg("sep", Builtin.unicode_type, None), + PyrexTypes.CFuncTypeArg("iterable", PyrexTypes.py_object_type, None), + ]) + + def _handle_simple_method_unicode_join(self, node, args, is_unbound_method): + """Replace unicode.join(...) by a direct call to the + corresponding C-API function. + """ + if len(args) != 2: + self._error_wrong_arg_count('unicode.join', node, args, 2) + return node + + return self._substitute_method_call( + node, "PyUnicode_Join", self.PyUnicode_Join_func_type, + 'join', is_unbound_method, args) + PyUnicode_Split_func_type = PyrexTypes.CFuncType( Builtin.list_type, [ PyrexTypes.CFuncTypeArg("str", Builtin.unicode_type, None),