Skip to content
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

Open
wants to merge 5 commits into
base: blead
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions builtin.c
Original file line number Diff line number Diff line change
Expand Up @@ -490,9 +490,12 @@ static OP *ck_builtin_func1(pTHX_ OP *entersubop, GV *namegv, SV *ckobj)
}
}

XS(XS_builtin_indexed)
/* This does not use the XS() macro so that op.c can see its prototype */
void
Perl_XS_builtin_indexed(pTHX_ CV *cv)
Comment on lines +493 to +495
Copy link
Contributor

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__)

{
dXSARGS;
PERL_ARGS_ASSERT_XS_BUILTIN_INDEXED;

switch(GIMME_V) {
case G_VOID:
Expand Down Expand Up @@ -638,7 +641,7 @@ static const struct BuiltinFuncDescriptor builtins[] = {
{ "load_module", NO_BUNDLE, &XS_builtin_load_module, &ck_builtin_func1, 0, true },

/* list functions */
{ "indexed", SHORTVER(5,39), &XS_builtin_indexed, &ck_builtin_funcN, 0, false },
{ "indexed", SHORTVER(5,39), &Perl_XS_builtin_indexed, &ck_builtin_funcN, 0, false },
{ "export_lexically", NO_BUNDLE, &XS_builtin_export_lexically, NULL, 0, true },

{ NULL, 0, NULL, NULL, 0, false }
Expand Down
2 changes: 2 additions & 0 deletions embed.fnc
Original file line number Diff line number Diff line change
Expand Up @@ -4087,6 +4087,8 @@ p |void |finish_export_lexical
p |void |import_builtin_bundle \
|U16 ver
p |void |prepare_export_lexical
p |void |XS_builtin_indexed \
|NN CV *cv
#endif
#if defined(PERL_IN_CLASS_C) || defined(PERL_IN_OP_C) || \
defined(PERL_IN_PAD_C) || defined(PERL_IN_PERLY_C) || \
Expand Down
1 change: 1 addition & 0 deletions embed.h
Original file line number Diff line number Diff line change
Expand Up @@ -1202,6 +1202,7 @@
# define get_aux_mg(a) S_get_aux_mg(aTHX_ a)
# endif
# if defined(PERL_IN_BUILTIN_C) || defined(PERL_IN_OP_C)
# define XS_builtin_indexed(a) Perl_XS_builtin_indexed(aTHX_ a)
# define finish_export_lexical() Perl_finish_export_lexical(aTHX)
# define import_builtin_bundle(a) Perl_import_builtin_bundle(aTHX_ a)
# define prepare_export_lexical() Perl_prepare_export_lexical(aTHX)
Expand Down
5 changes: 1 addition & 4 deletions op.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,6 @@ recursive, but it's recursive on basic blocks, not on tree nodes.

static const char array_passed_to_stat[] = "Array passed to stat will be coerced to a scalar";

/* UGH!! */
EXTERN_C void XS_builtin_indexed(pTHX_ CV *);

/* remove any leading "empty" ops from the op_next chain whose first
* node's address is stored in op_p. Store the updated address of the
* first node in op_p.
Expand Down Expand Up @@ -9825,7 +9822,7 @@ Perl_newFOROP(pTHX_ I32 flags, OP *sv, OP *expr, OP *block, OP *cont)
if(firstarg == lastarg)
firstarg = NULL;

if (op_is_cv_xsub(lastarg, &XS_builtin_indexed) && /* a call to builtin::indexed */
if (op_is_cv_xsub(lastarg, &Perl_XS_builtin_indexed) && /* a call to builtin::indexed */
firstarg && OpSIBLING(firstarg) == lastarg && /* with one arg */
(firstarg->op_type == OP_RV2AV || firstarg->op_type == OP_PADAV) /* ... which is an array */
) {
Expand Down
6 changes: 6 additions & 0 deletions proto.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading