Commit ae9630e5 authored by Robert Bradshaw's avatar Robert Bradshaw

Fix speed regression due to PySequence_Fast in for loop.

PySequence_Fast isn't so fast after all (due to multiple branching),
was a 35% slowdown for looping over lists. Now it handles tuples as
well with only about a 4% slowdown to lists compared to before.
parent 8958817f
......@@ -1169,20 +1169,24 @@ class NextNode(AtomicExprNode):
self.is_temp = 1
def generate_result_code(self, code):
code.putln(
"if (likely(%s != -1)) {" % self.iterator.counter.result_code)
code.putln(
"if (%s >= PySequence_Fast_GET_SIZE(%s)) break;" % (
self.iterator.counter.result_code,
self.iterator.py_result()))
code.putln(
"%s = PySequence_Fast_GET_ITEM(%s, %s); Py_INCREF(%s); %s++;" % (
self.result_code,
self.iterator.py_result(),
self.iterator.counter.result_code,
self.result_code,
self.iterator.counter.result_code))
code.putln("} else {")
for py_type in ["List", "Tuple"]:
code.putln(
"if (likely(Py%s_CheckExact(%s))) {" % (py_type, self.iterator.py_result()))
code.putln(
"if (%s >= Py%s_GET_SIZE(%s)) break;" % (
self.iterator.counter.result_code,
py_type,
self.iterator.py_result()))
code.putln(
"%s = Py%s_GET_ITEM(%s, %s); Py_INCREF(%s); %s++;" % (
self.result_code,
py_type,
self.iterator.py_result(),
self.iterator.counter.result_code,
self.result_code,
self.iterator.counter.result_code))
code.put("} else ")
code.putln("{")
code.putln(
"%s = PyIter_Next(%s);" % (
self.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