From: Stefan Behnel Date: Mon, 17 May 2010 11:23:31 +0000 (+0200) Subject: make len(Py_UNICODE) efficient X-Git-Tag: 0.13.beta0~74 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=cabf946ed91b3f055a9dc339fd03e2d29c57fdc1;p=cython.git make len(Py_UNICODE) efficient --- diff --git a/Cython/Compiler/Optimize.py b/Cython/Compiler/Optimize.py index 3ec67623..e874a75b 100644 --- a/Cython/Compiler/Optimize.py +++ b/Cython/Compiler/Optimize.py @@ -1540,6 +1540,9 @@ class OptimizeBuiltinCalls(Visitor.EnvTransform): node.pos, cfunc_name, self.PyObject_Size_func_type, args = [arg], is_temp = node.is_temp) + elif arg.type is PyrexTypes.c_py_unicode_type: + return ExprNodes.IntNode(node.pos, value='1', constant_result=1, + type=node.type) else: return node if node.type not in (PyrexTypes.c_size_t_type, PyrexTypes.c_py_ssize_t_type): diff --git a/tests/run/py_unicode_type.pyx b/tests/run/py_unicode_type.pyx index 5a93cc73..c7283144 100644 --- a/tests/run/py_unicode_type.pyx +++ b/tests/run/py_unicode_type.pyx @@ -119,3 +119,13 @@ def unicode_methods(Py_UNICODE uchar): uchar.upper(), uchar.title(), ] + +@cython.test_assert_path_exists('//IntNode') +@cython.test_fail_if_path_exists('//SimpleCallNode', + '//PythonCapiCallNode') +def len_uchar(Py_UNICODE uchar): + """ + >>> len_uchar(ord('A')) + 1 + """ + return len(uchar)