Skip to content

Commit ebe37f6

Browse files
committed
Add support for the new OP_MULTIDEREF
Perl has a new op, added as a performance optimisation in fedf30e1c349130b23648c022f5f3cb4ad7928f3, to represent a sequence of array/hash dereferences. This patch adds support for the new op.
1 parent 72932e3 commit ebe37f6

File tree

4 files changed

+63
-3
lines changed

4 files changed

+63
-3
lines changed

Changes

+5
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,8 @@ Revision history for Perl extension Want.
119119
0.24 Tue 2 Dec 2014 10:22:39 GMT
120120
- Accommodate another bleadperl change. Patch provided by Father Chrysostomos at
121121
https://rt.cpan.org/Public/Bug/Display.html?id=100626
122+
123+
0.25 Wed 10 Dec 2014 19:31:03 GMT
124+
- Add support for the new OP_MULTIDEREF
125+
Perl has a new op, added as a performance optimisation in fedf30e1c349130b23648c022f5f3cb4ad7928f3,
126+
to represent a sequence of array/hash dereferences. This patch adds support for the new op.

README

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
-----------------------------------------------------------------------------
2-
| Want v0.24 - Robin Houston, 2014-12-02
2+
| Want v0.25 - Robin Houston, 2014-12-10
33
-----------------------------------------------------------------------------
44

55
For full documentation, see the POD included with the module.

Want.pm

+6-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ our @ISA = qw(Exporter DynaLoader);
1212

1313
our @EXPORT = qw(want rreturn lnoreturn);
1414
our @EXPORT_OK = qw(howmany wantref);
15-
our $VERSION = '0.24';
15+
our $VERSION = '0.25';
1616

1717
bootstrap Want $VERSION;
1818

@@ -128,7 +128,8 @@ sub howmany () {
128128
}
129129

130130
sub wantref {
131-
my $n = parent_op_name(bump_level(@_, 1));
131+
my $level = bump_level(@_, 1);
132+
my $n = parent_op_name($level);
132133
if ($n eq 'rv2av') {
133134
return "ARRAY";
134135
}
@@ -147,6 +148,9 @@ sub wantref {
147148
elsif ($n eq 'method_call') {
148149
return 'OBJECT';
149150
}
151+
elsif ($n eq 'multideref') {
152+
return first_multideref_type($level);
153+
}
150154
else {
151155
return "";
152156
}

Want.xs

+51
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,57 @@ I32 uplevel;
543543
PUSHs(sv_2mortal(newSVpv(retval, 0)));
544544
}
545545

546+
#ifdef OPpMULTIDEREF_EXISTS
547+
char*
548+
first_multideref_type(uplevel)
549+
I32 uplevel;
550+
PREINIT:
551+
OP *r;
552+
OP *o = parent_op(uplevel, &r);
553+
UNOP_AUX_item *items;
554+
UV actions;
555+
bool repeat;
556+
char *retval;
557+
PPCODE:
558+
if (o->op_type != OP_MULTIDEREF) Perl_croak(aTHX_ "Not a multideref op!");
559+
items = cUNOP_AUXx(o)->op_aux;
560+
actions = items->uv;
561+
562+
do {
563+
repeat = FALSE;
564+
switch (actions & MDEREF_ACTION_MASK) {
565+
case MDEREF_reload:
566+
actions = (++items)->uv;
567+
repeat = TRUE;
568+
continue;
569+
570+
case MDEREF_AV_pop_rv2av_aelem:
571+
case MDEREF_AV_gvsv_vivify_rv2av_aelem:
572+
case MDEREF_AV_padsv_vivify_rv2av_aelem:
573+
case MDEREF_AV_vivify_rv2av_aelem:
574+
case MDEREF_AV_padav_aelem:
575+
case MDEREF_AV_gvav_aelem:
576+
retval = "ARRAY";
577+
break;
578+
579+
case MDEREF_HV_pop_rv2hv_helem:
580+
case MDEREF_HV_gvsv_vivify_rv2hv_helem:
581+
case MDEREF_HV_padsv_vivify_rv2hv_helem:
582+
case MDEREF_HV_vivify_rv2hv_helem:
583+
case MDEREF_HV_padhv_helem:
584+
case MDEREF_HV_gvhv_helem:
585+
retval = "HASH";
586+
break;
587+
588+
default:
589+
Perl_croak(aTHX_ "Unrecognised OP_MULTIDEREF action (%lu)!", actions & MDEREF_ACTION_MASK);
590+
}
591+
} while (repeat);
592+
593+
EXTEND(SP, 1);
594+
PUSHs(sv_2mortal(newSVpv(retval, 0)));
595+
596+
#endif
546597

547598
I32
548599
want_count(uplevel)

0 commit comments

Comments
 (0)