-
Notifications
You must be signed in to change notification settings - Fork 555
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimise foreach on builtin::indexed ARRAY #22641
base: blead
Are you sure you want to change the base?
Conversation
This change does have the potential impact that, before it, any modifications to the iterated-on array that happen during the body of its own |
bf454f3
to
03618f2
Compare
f3d8512
to
38d31c3
Compare
…e OP_ENTERITER and not OP_ITER
…cals Rather than generating an entire temporary list that is twice as big as the original array, instead set a flag on the `OP_ITER` that tells it to set one of the iteration variables to the current array index and use the same `CXt_LOOP_ARY` optimisation that regular foreach over an array would use.
…op.c can take its address
38d31c3
to
2f2b892
Compare
/* This does not use the XS() macro so that op.c can see its prototype */ | ||
void | ||
Perl_XS_builtin_indexed(pTHX_ CV *cv) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
builtin.c: In function ‘Perl_XS_builtin_indexed’:
builtin.c:495:35: warning: unused parameter ‘cv’ [-Wunused-parameter]
495 | Perl_XS_builtin_indexed(pTHX_ CV *cv)
| ~~~~^~
Normally suppressed by the attribute in :
#define XSPROTO(name) void name(pTHX_ CV* cv __attribute__unused__)
Deparse needs an update:
|
Looks ok otherwise |
Consistency seems good, and the foreach docs basically say "don't do this" already. But maybe this change should have a brief mention in perldelta, since this feature isnt experimental anymore? |
Rather than generating an entire temporary list that is twice as big as the original array, instead set a flag on the
OP_ITER
that tells it to set one of the iteration variables to the current array index and use the sameCXt_LOOP_ARY
optimisastion that regular foreach over an array would use.Consider whether
builtin::indexed LIST...
should do the same optimisation. Likely the answer is "yes", but in a separate change.This set of changes requires a perldelta entry, and it is included