diff options
author | Tassilo von Parseval <tassilo.parseval@post.rwth-aachen.de> | 2004-02-24 13:02:57 +0100 |
---|---|---|
committer | Rafael Garcia-Suarez <rgarciasuarez@gmail.com> | 2004-02-24 19:53:51 +0000 |
commit | 22023b2636bf15292e047d7ecd514d472b7abffc (patch) | |
tree | 4ab4004aa56eded67011152f4d3c3d479447d507 /pp_ctl.c | |
parent | 16e8b84077a7f90c46bd95640feeb546b4bfbf75 (diff) | |
download | perl-22023b2636bf15292e047d7ecd514d472b7abffc.tar.gz |
optimization for map in scalar context
Message-id: <20040224110257.GA5510@ethan>
p4raw-id: //depot/perl@22369
Diffstat (limited to 'pp_ctl.c')
-rw-r--r-- | pp_ctl.c | 15 |
1 files changed, 13 insertions, 2 deletions
@@ -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 */ |