diff options
author | David Mitchell <davem@iabyn.com> | 2017-07-19 16:50:14 +0100 |
---|---|---|
committer | David Mitchell <davem@iabyn.com> | 2017-07-27 11:30:24 +0100 |
commit | 3cd2c7d486f06a3e4bc31c2f5afc51e5224fcac5 (patch) | |
tree | 64d973634771d438b68ec63a4ec9f4ac7e7908f0 /pp_hot.c | |
parent | 0b5aba47e85e02bdba9d9d90643d7928ac50cc80 (diff) | |
download | perl-3cd2c7d486f06a3e4bc31c2f5afc51e5224fcac5.tar.gz |
simplify keys(%tied_hash) in boolean context.
Previously something like
if (keys %tied_hash) { ... }
would have called FIRSTKEY(), followed by NEXTKEY() x N.
Now, it just calls SCALAR() once if present, and if not, falls
back to calling just FIRSTKEY() once.
i.e. it only needs to determine whether at least one key is present.
The behaviour of of 'keys(%tied) in boolean context now matches that of
'(%tied) in boolean context.
See http://nntp.perl.org/group/perl.perl5.porters/245463.
Diffstat (limited to 'pp_hot.c')
-rw-r--r-- | pp_hot.c | 9 |
1 files changed, 6 insertions, 3 deletions
@@ -993,9 +993,12 @@ S_padhv_rv2hv_common(pTHX_ HV *hv, U8 gimme, bool is_keys, bool has_targ) || ( PL_op->op_private & OPpMAYBE_TRUEBOOL && block_gimme() == G_VOID) ) - && !tied - ) - PUSHs(HvUSEDKEYS(hv) ? &PL_sv_yes : &PL_sv_zero); + ) { + if (tied) + PUSHs(Perl_hv_scalar(aTHX_ hv)); + else + PUSHs(HvUSEDKEYS(hv) ? &PL_sv_yes : &PL_sv_zero); + } else if (gimme == G_SCALAR) { if (is_keys) { IV i; |