Commit cabf946e authored by Stefan Behnel's avatar Stefan Behnel

make len(Py_UNICODE) efficient

parent 8bb823ab
...@@ -1540,6 +1540,9 @@ class OptimizeBuiltinCalls(Visitor.EnvTransform): ...@@ -1540,6 +1540,9 @@ class OptimizeBuiltinCalls(Visitor.EnvTransform):
node.pos, cfunc_name, self.PyObject_Size_func_type, node.pos, cfunc_name, self.PyObject_Size_func_type,
args = [arg], args = [arg],
is_temp = node.is_temp) 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: else:
return node return node
if node.type not in (PyrexTypes.c_size_t_type, PyrexTypes.c_py_ssize_t_type): if node.type not in (PyrexTypes.c_size_t_type, PyrexTypes.c_py_ssize_t_type):
......
...@@ -119,3 +119,13 @@ def unicode_methods(Py_UNICODE uchar): ...@@ -119,3 +119,13 @@ def unicode_methods(Py_UNICODE uchar):
uchar.upper(), uchar.upper(),
uchar.title(), 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)
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