Skip to content

Commit 1fa32b2

Browse files
committed
Add comments based on review feedback
1 parent c33a683 commit 1fa32b2

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

mypyc/irbuild/statement.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,12 @@ def emit_yield_from_or_await(
938938
and isinstance(val.type, RInstance)
939939
and val.type.class_ir.has_method(helper_method)
940940
):
941-
# This is a generated generator class, and we can use a fast path.
941+
# This is a generated native generator class, and we can use a fast path.
942+
# This allows two optimizations:
943+
# 1) No need to call CPy_GetCoro() or iter() since for native generators
944+
# it just returns the generator object (implemented here).
945+
# 2) Instead of calling next(), call generator helper method directly,
946+
# since next() just calls __next__ which calls the helper method.
942947
iter_val: Value = val
943948
else:
944949
get_op = coro_op if is_await else iter_op
@@ -952,6 +957,7 @@ def emit_yield_from_or_await(
952957
stop_block, main_block, done_block = BasicBlock(), BasicBlock(), BasicBlock()
953958

954959
if isinstance(iter_reg.type, RInstance) and iter_reg.type.class_ir.has_method(helper_method):
960+
# Second fast path optimization: call helper directly (see also comment above).
955961
obj = builder.read(iter_reg)
956962
nn = builder.none_object()
957963
m = MethodCall(obj, helper_method, [nn, nn, nn, nn], line)

0 commit comments

Comments
 (0)