Commit 8d73ea74 authored by Stefan Behnel's avatar Stefan Behnel

safe a few cycles (~4%) when calling 'in' on dicts

parent 82d6bc7d
...@@ -4827,14 +4827,31 @@ class CmpNode(object): ...@@ -4827,14 +4827,31 @@ class CmpNode(object):
if 'not' in op: negation = "!" if 'not' in op: negation = "!"
else: negation = "" else: negation = ""
if op == 'in' or op == 'not_in': if op == 'in' or op == 'not_in':
code.putln( if operand2.type is dict_type:
"%s = %s(%sPySequence_Contains(%s, %s)); %s" % ( code.globalstate.use_utility_code(
result_code, raise_none_iter_error_utility_code)
coerce_result, code.putln("if (unlikely(%s == Py_None)) {" % operand2.py_result())
negation, code.putln("__Pyx_RaiseNoneNotIterableError(); %s" %
operand2.py_result(), code.error_goto(self.pos))
operand1.py_result(), code.putln("} else {")
code.error_goto_if_neg(result_code, self.pos))) code.putln(
"%s = %s(%sPyDict_Contains(%s, %s)); %s" % (
result_code,
coerce_result,
negation,
operand2.py_result(),
operand1.py_result(),
code.error_goto_if_neg(result_code, self.pos)))
code.putln("}")
else:
code.putln(
"%s = %s(%sPySequence_Contains(%s, %s)); %s" % (
result_code,
coerce_result,
negation,
operand2.py_result(),
operand1.py_result(),
code.error_goto_if_neg(result_code, self.pos)))
elif (operand1.type.is_pyobject elif (operand1.type.is_pyobject
and op not in ('is', 'is_not')): and op not in ('is', 'is_not')):
code.putln("%s = PyObject_RichCompare(%s, %s, %s); %s" % ( code.putln("%s = PyObject_RichCompare(%s, %s, %s); %s" % (
......
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