summaryrefslogtreecommitdiff
path: root/pp_ctl.c
diff options
context:
space:
mode:
authorTassilo von Parseval <tassilo.parseval@post.rwth-aachen.de>2004-02-24 13:02:57 +0100
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>2004-02-24 19:53:51 +0000
commit22023b2636bf15292e047d7ecd514d472b7abffc (patch)
tree4ab4004aa56eded67011152f4d3c3d479447d507 /pp_ctl.c
parent16e8b84077a7f90c46bd95640feeb546b4bfbf75 (diff)
downloadperl-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.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/pp_ctl.c b/pp_ctl.c
index e91ff540e0..26fb164a6b 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 */