Commit e1ae63dd authored by Stefan Behnel's avatar Stefan Behnel

Refactor some code repetition into a loop.

parent e801d21a
...@@ -12192,27 +12192,22 @@ class CmpNode(object): ...@@ -12192,27 +12192,22 @@ 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 [
self.operand2 = self.operand2.as_none_safe_node("'NoneType' object is not iterable") ('Dict', Builtin.dict_type),
self.special_bool_cmp_utility_code = UtilityCode.load_cached("PyDictContains", "ObjectHandling.c") ('Set', Builtin.set_type),
self.special_bool_cmp_function = "__Pyx_PyDict_ContainsTF" ('Unicode', Builtin.unicode_type)]:
return True if self.operand2.type is special_type:
elif self.operand2.type is Builtin.set_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") break
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.
return True 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 False return False
def generate_operation_code(self, code, result_code, def generate_operation_code(self, code, result_code,
......
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