Commit 74a20277 authored by Stefan Behnel's avatar Stefan Behnel

drop redundant specialisation code from for-in loop if we know it's not a list or tuple

parent 2fd9231a
......@@ -1519,14 +1519,16 @@ class IteratorNode(ExprNode):
def generate_result_code(self, code):
is_builtin_sequence = self.sequence.type is list_type or \
self.sequence.type is tuple_type
may_be_a_sequence = is_builtin_sequence or not self.sequence.type.is_builtin_type
if is_builtin_sequence:
code.putln(
"if (likely(%s != Py_None)) {" % self.sequence.py_result())
else:
elif may_be_a_sequence:
code.putln(
"if (PyList_CheckExact(%s) || PyTuple_CheckExact(%s)) {" % (
self.sequence.py_result(),
self.sequence.py_result()))
if may_be_a_sequence:
code.putln(
"%s = 0; %s = %s; __Pyx_INCREF(%s);" % (
self.counter_cname,
......@@ -1545,6 +1547,7 @@ class IteratorNode(ExprNode):
self.sequence.py_result(),
code.error_goto_if_null(self.result(), self.pos)))
code.put_gotref(self.py_result())
if may_be_a_sequence:
code.putln("}")
......@@ -1564,12 +1567,15 @@ class NextNode(AtomicExprNode):
self.is_temp = 1
def generate_result_code(self, code):
if self.iterator.sequence.type is list_type:
sequence_type = self.iterator.sequence.type
if sequence_type is list_type:
type_checks = [(list_type, "List")]
elif self.iterator.sequence.type is tuple_type:
elif sequence_type is tuple_type:
type_checks = [(tuple_type, "Tuple")]
else:
elif not sequence_type.is_builtin_type:
type_checks = [(list_type, "List"), (tuple_type, "Tuple")]
else:
type_checks = []
for py_type, prefix in type_checks:
if len(type_checks) > 1:
......
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