Commit ae84b380 authored by Stefan Behnel's avatar Stefan Behnel

partial optimisation for ord(Py_UNICODE) - better optimisation that returns a...

partial optimisation for ord(Py_UNICODE) - better optimisation that returns a C integer result requires type analysis refactoring
parent 5bd4e9b6
...@@ -1939,6 +1939,17 @@ class OptimizeBuiltinCalls(Visitor.EnvTransform): ...@@ -1939,6 +1939,17 @@ class OptimizeBuiltinCalls(Visitor.EnvTransform):
test_node = UtilNodes.EvalWithTempExprNode(temp, test_node) test_node = UtilNodes.EvalWithTempExprNode(temp, test_node)
return test_node return test_node
def _handle_simple_function_ord(self, node, pos_args):
"""Unpack ord(Py_UNICODE).
"""
if len(pos_args) != 1:
return node
arg = pos_args[0]
if isinstance(arg, ExprNodes.CoerceToPyTypeNode):
if arg.arg.type is PyrexTypes.c_py_unicode_type:
return arg.arg.coerce_to(node.type, self.current_env())
return node
### special methods ### special methods
Pyx_tp_new_func_type = PyrexTypes.CFuncType( Pyx_tp_new_func_type = PyrexTypes.CFuncType(
......
cimport cython
ustring_with_a = u'abcdefg'
ustring_without_a = u'bcdefg'
@cython.test_fail_if_path_exists('//SimpleCallNode')
def unicode_for_loop_ord(unicode s):
"""
>>> unicode_for_loop_ord(ustring_with_a)
True
>>> unicode_for_loop_ord(ustring_without_a)
False
"""
for c in s:
if ord(c) == u'a':
return True
return False
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