Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.

Commit 1e6df78

Browse files
committed
oelemfast: rewrite
1 parent 570428d commit 1e6df78

File tree

4 files changed

+33
-42
lines changed

4 files changed

+33
-42
lines changed

op.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23456,6 +23456,7 @@ S_do_method_finalize(pTHX_ const HV *klass, const CV* cv,
2345623456
SVfARG(cv_name((CV*)cv, NULL, CV_NAME_NOMAIN)),
2345723457
SvPVX(meth), (int)self, (int)ix));
2345823458
f->op_targ = self;
23459+
/* keeps OPf_MOD */
2345923460
OpTYPE_set(f, OP_OELEMFAST); /* PUSHMARK is the bb leader,
2346023461
not ENTERSUB. Some next might point
2346123462
to it */

opcode.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,7 +1014,7 @@ PL_op_type_str[] = {
10141014
"(:Scalar,:Scalar):Scalar", /* 13: sassign */
10151015
"(:List,:List):List", /* 14: aassign */
10161016
"(:Ref,:Str):Any", /* 15: oelem */
1017-
"(:Ref,:Int):Any", /* 16: oelemfast */
1017+
"():Any", /* 16: oelemfast */
10181018
"(:List(:Str)):Scalar", /* 17: chop */
10191019
"(:Str):Int", /* 18: schop */
10201020
"(:List(:Str)):Scalar", /* 19: chomp */
@@ -1443,7 +1443,7 @@ EXTCONST U32 PL_op_type[] = {
14431443
0x0b0bff0b, /* 13: sassign "(:Scalar,:Scalar):Scalar" */
14441444
0x1212ff12, /* 14: aassign "(:List,:List):List" */
14451445
0x0c08ff13, /* 15: oelem "(:Ref,:Str):Any" */
1446-
0x0c05ff13, /* 16: oelemfast "(:Ref,:Int):Any" */
1446+
0xffffff13, /* 16: oelemfast "():Any" */
14471447
0xa8ffff0b, /* 17: chop "(:List(:Str)):Scalar" */
14481448
0x08ffff05, /* 18: schop "(:Str):Int" */
14491449
0xa8ffff0b, /* 19: chomp "(:List(:Str)):Scalar" */
@@ -3188,7 +3188,7 @@ EXTCONST U32 PL_opargs[] = {
31883188
0x00044804, /* sassign */
31893189
0x00088808, /* aassign */
31903190
0x0005c800, /* oelem */
3191-
0x0021c000, /* oelemfast */
3191+
0x00000000, /* oelemfast */
31923192
0x0000a80d, /* chop */
31933193
0x0002688c, /* schop */
31943194
0x0000a81d, /* chomp */

pp.c

Lines changed: 28 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -373,54 +373,44 @@ PPt(pp_oelem, "(:Ref,:Str):Any")
373373
ditto ix for a valid field index.
374374
fields may be also arrays or hashes.
375375
*/
376-
PPt(pp_oelemfast, "(:Ref,:Int):Any")
376+
PPt(pp_oelemfast, "():Any")
377377
{
378378
dSP;
379-
SV * const obj = PAD_SVl(PL_op->op_targ);
380-
const U8 ix = PL_op->op_private;
381-
const bool lvalue = cBOOL((PL_op->op_flags & OPf_MOD || LVRET));
382-
/*HV * klass;
379+
SV * const obj = SvRV(PAD_SVl(PL_op->op_targ));
380+
const U8 ix = PL_op->op_private;
381+
const bool lval = PL_op->op_flags & OPf_MOD;
382+
SV** ary;
383+
HV * klass;
383384

384-
if (UNLIKELY(!obj || SvOBJECT(obj) || !(klass = SvSTASH(obj)) || !SvOOK(klass)
385-
|| !SvROK(obj) || SvTYPE(SvRV(obj)) != SVt_PVAV))
385+
#ifdef DEBUGGING
386+
if (UNLIKELY(!obj || !SvOBJECT(obj) || !(klass = SvSTASH(obj)) || !SvOOK(klass)
387+
|| SvTYPE(obj) != SVt_PVAV))
386388
DIE(aTHX_ "Invalid object");
387389
if (UNLIKELY(!HvCLASS(klass))) {
388390
const char *name = HvNAME_get(klass) ? HEK_KEY(HvNAME_HEK_NN(klass)) : "__ANON__";
389391
Perl_die(aTHX_ "Not a class %s", name);
390-
}*/
391-
EXTEND(SP, 1);
392-
PUSHs(AvARRAY(MUTABLE_AV(SvRV(obj)))[ix]);
393-
if (lvalue && !TOPs) {
394-
HV *klass = SvSTASH(obj);
395-
#if 0
396-
GV *fields;
397-
SV *name = newSVpvn_flags(HvNAME(klass), HvNAMELEN(klass),
398-
HvNAMEUTF8(klass)|SVs_TEMP);
399-
/*SV *name = newSVhek(HvNAME_HEK_NN(klass));*/
400-
assert(HvCLASS(klass));
401-
sv_catpvs(name, "::FIELDS");
402-
fields = gv_fetchsv(name, 0, SVt_PVAV);
403-
assert(fields && GvAV(fields));
404-
{
405-
SV *pad = AvARRAY(GvAV(fields))[ix];
406-
const PADOFFSET po = SvIVX(pad);
407-
assert(SvIOK(pad));
392+
}
408393
#else
409-
assert(HvCLASS(klass));
410-
{
411-
const PADOFFSET po = field_index(klass, ix);
394+
klass = SvSTASH(obj);
412395
#endif
413-
const PADNAME* pn = PAD_COMPNAME(po);
414-
/* XXX typed? */
415-
416-
if (*PadnamePV(pn) == '$')
417-
PUSHs(newSV(0));
418-
else if (*PadnamePV(pn) == '@')
419-
PUSHs(newSV_type(SVt_PVAV));
420-
else if (*PadnamePV(pn) == '%')
421-
PUSHs(newSV_type(SVt_PVHV));
422-
}
396+
EXTEND(SP, 1);
397+
assert(HvCLASS(klass));
398+
ary = AvARRAY(MUTABLE_AV(obj));
399+
assert(ary);
400+
if (lval && !ary[ix]) { /* init NULL value */
401+
const PADOFFSET po = field_index(klass, ix);
402+
const char c = *PAD_COMPNAME_PV(po);
403+
/* XXX typed? */
404+
if (c == '$')
405+
ary[ix] = newSV(0);
406+
else if (c == '@')
407+
ary[ix] = newSV_type(SVt_PVAV);
408+
else if (c == '%')
409+
ary[ix] = newSV_type(SVt_PVHV);
410+
PUSHs(ary[ix]);
411+
RETURN;
423412
}
413+
PUSHs(ary[ix] ? ary[ix] : UNDEF);
424414
RETURN;
425415
}
426416

regen/opcodes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ padany private value ck_null d0 "():Void"
6666
sassign scalar assignment ck_sassign s2 S S "(:Scalar,:Scalar):Scalar"
6767
aassign list assignment ck_aassign t2 L L "(:List,:List):List"
6868
oelem object element ck_null 2 R S "(:Ref,:Str):Any"
69-
oelemfast constant object element ck_null 0 R I "(:Ref,:Int):Any"
69+
oelemfast constant object element ck_null 0 "():Any"
7070

7171
chop chop ck_spair mts% L "(:List(:Str)):Scalar"
7272
schop scalar chop ck_null stu% S? "(:Str):Int"

0 commit comments

Comments
 (0)