@@ -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
0 commit comments