Commit fa866395 authored by Marius Wachtler's avatar Marius Wachtler

Generator: don't generate the traceback for the StopIteration exc when the...

Generator: don't generate the traceback for the StopIteration exc when the generator is exiting back to a hasnext call.
This is a small perf improvement for django-template.py: took  7.4ms for last iteration from 8.2ms
parent 05fb51ad
...@@ -161,7 +161,10 @@ static void generatorSendInternal(BoxedGenerator* self, Box* v) { ...@@ -161,7 +161,10 @@ static void generatorSendInternal(BoxedGenerator* self, Box* v) {
if (self->entryExited) { if (self->entryExited) {
freeGeneratorStack(self); freeGeneratorStack(self);
self->exception = excInfoForRaise(StopIteration, None, None); // Reset the current exception.
// We could directly create the StopIteration exception but we delay creating it because often the caller is not
// interested in the exception (=generatorHasnext). If we really need it we will create it inside generatorSend.
self->exception = ExcInfo(NULL, NULL, NULL);
return; return;
} }
} }
...@@ -184,9 +187,11 @@ Box* generatorSend(Box* s, Box* v) { ...@@ -184,9 +187,11 @@ Box* generatorSend(Box* s, Box* v) {
// create a new one if the generator exited implicit. // create a new one if the generator exited implicit.
// CPython raises the custom exception just once, on the next generator 'next' it will we a normal StopIteration // CPython raises the custom exception just once, on the next generator 'next' it will we a normal StopIteration
// exc. // exc.
assert(self->exception.matches(StopIteration)); assert(self->exception.type == NULL || self->exception.matches(StopIteration));
ExcInfo old_exc = self->exception; ExcInfo old_exc = self->exception;
self->exception = excInfoForRaise(StopIteration, None, None); self->exception = excInfoForRaise(StopIteration, None, None);
if (old_exc.type == NULL)
old_exc = self->exception;
raiseRaw(old_exc); raiseRaw(old_exc);
} }
......
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