From 14e337706f61df74527d6378856b990896ba2912 Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Sun, 21 Mar 2010 08:39:29 +0100 Subject: [PATCH] optimise unicode.join() --- Cython/Compiler/Optimize.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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), -- 2.26.2