Commit e1ae63dd authored by Stefan Behnel's avatar Stefan Behnel

Refactor some code repetition into a loop.

parent e801d21a
...@@ -12192,26 +12192,21 @@ class CmpNode(object): ...@@ -12192,26 +12192,21 @@ class CmpNode(object):
self.special_bool_cmp_function = "__Pyx_PyString_Equals" self.special_bool_cmp_function = "__Pyx_PyString_Equals"
return True return True
elif self.operator in ('in', 'not_in'): elif self.operator in ('in', 'not_in'):
if self.operand2.type is Builtin.dict_type: for type_name, special_type in [
('Dict', Builtin.dict_type),
('Set', Builtin.set_type),
('Unicode', Builtin.unicode_type)]:
if self.operand2.type is special_type:
self.operand2 = self.operand2.as_none_safe_node("'NoneType' object is not iterable") self.operand2 = self.operand2.as_none_safe_node("'NoneType' object is not iterable")
self.special_bool_cmp_utility_code = UtilityCode.load_cached("PyDictContains", "ObjectHandling.c") break
self.special_bool_cmp_function = "__Pyx_PyDict_ContainsTF"
return True
elif self.operand2.type is Builtin.set_type:
self.operand2 = self.operand2.as_none_safe_node("'NoneType' object is not iterable")
self.special_bool_cmp_utility_code = UtilityCode.load_cached("PySetContains", "ObjectHandling.c")
self.special_bool_cmp_function = "__Pyx_PySet_ContainsTF"
return True
elif self.operand2.type is Builtin.unicode_type:
self.operand2 = self.operand2.as_none_safe_node("'NoneType' object is not iterable")
self.special_bool_cmp_utility_code = UtilityCode.load_cached("PyUnicodeContains", "StringTools.c")
self.special_bool_cmp_function = "__Pyx_PyUnicode_ContainsTF"
return True
else: else:
if not self.operand2.type.is_pyobject: if not self.operand2.type.is_pyobject:
self.operand2 = self.operand2.coerce_to_pyobject(env) self.operand2 = self.operand2.coerce_to_pyobject(env)
self.special_bool_cmp_utility_code = UtilityCode.load_cached("PySequenceContains", "ObjectHandling.c") type_name = 'Sequence'
self.special_bool_cmp_function = "__Pyx_PySequence_ContainsTF" # map to utility functions PySequenceContains, PySetContains, PyDictContains etc.
self.special_bool_cmp_utility_code = UtilityCode.load_cached(
"Py%sContains" % type_name, "ObjectHandling.c")
self.special_bool_cmp_function = "__Pyx_Py%s_ContainsTF" % type_name
return True return True
return False 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