From: Tassilo von Parseval Date: Tue, 24 Feb 2004 12:02:57 +0000 (+0100) Subject: optimization for map in scalar context X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=22023b2636bf15292e047d7ecd514d472b7abffc;p=p5sagit%2Fp5-mst-13.2.git optimization for map in scalar context Message-id: <20040224110257.GA5510@ethan> p4raw-id: //depot/perl@22369 --- diff --git a/pp_ctl.c b/pp_ctl.c index e91ff54..26fb164 100644 --- a/pp_ctl.c +++ b/pp_ctl.c @@ -939,8 +939,19 @@ PP(pp_mapwhile) } /* copy the new items down to the destination list */ dst = PL_stack_base + (PL_markstack_ptr[-2] += items) - 1; - while (items-- > 0) - *dst-- = SvTEMP(TOPs) ? POPs : sv_mortalcopy(POPs); + if (gimme == G_ARRAY) { + while (items-- > 0) + *dst-- = SvTEMP(TOPs) ? POPs : sv_mortalcopy(POPs); + } + else { + /* scalar context: we don't care about which values map returns + * (we use undef here). And so we certainly don't want to do mortal + * copies of meaningless values. */ + while (items-- > 0) { + POPs; + *dst-- = &PL_sv_undef; + } + } } LEAVE; /* exit inner scope */