This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #114576] Optimise if(%hash) in non-void context
authorFather Chrysostomos <sprout@cpan.org>
Sat, 25 Aug 2012 06:52:36 +0000 (23:52 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Sat, 25 Aug 2012 06:53:02 +0000 (23:53 -0700)
commit20e53f5f001b3fda5eb8b7723aea90459e2a5399
treed50152ce16c1bd698f4d2862e28f7a7b1b29bfc1
parent3c30bf984aa27d52d7c70ff8ce9275b74bb1af49
[perl #114576] Optimise if(%hash) in non-void context

The boolkeys optimisation (867fa1e2da1) was only applying to an and
(or if) in void context.  If an if occurs as the last thing in a sub-
routine, the void context is not know at compile time so the optimisa-
tion does not apply.

In the case of || (to which the boolkeys optimisation also applies),
we can’t optimise it in non-void context, because someone might be
writing $bucket_info = %hash || '0/0';

In the case of &&, we can optimise it, even in non-void context,
because a true value will always be discarded in %hash && foo.
The false value it returns for an empty hash is always the int-
eger 0.  That would change if we simply applied boolkeys to
my $ret = %hash && foo; because boolkeys return &PL_sv_no (the dualvar
you get from !1).  But since boolkeys’ return value is never directly
visible to perl code, we can safely change that.
op.c
pp.c