develooper Front page | perl.perl5.porters | Postings from February 2006

Merging hasargs and lval in struct block_sub

From:
Nicholas Clark
Date:
February 23, 2006 11:34
Subject:
Merging hasargs and lval in struct block_sub
Message ID:
20060223193421.GB616@plum.flirble.org
In cop.h there's this comment:


/* subroutine context */
struct block_sub {
    CV *	cv;
    GV *	gv;
    GV *	dfoutgv;
    AV *	savearray;
    AV *	argarray;
    long	olddepth;
    U8		hasargs;
    U8		lval;		/* XXX merge lval and hasargs? */
    PAD		*oldcomppad;
    OP *	retop;	/* op to execute on exit from sub */
};


For the record, I attempted this using the appended patch, and the perl
binary gets about 200 bytes larger. As I think that the saving in the
structure is only going to be 4 bytes, this suggests to me that it's only a
space win if more than 50 block_sub structures exist, which doesn't seem
that likely. So I didn't think that this was worth it.

Nicholas Clark

==== //depot/perl/cop.h#107 - /export/home/nwc10/p4perl/perl/cop.h ====
--- /tmp/tmp.30782.0	Thu Feb 23 19:30:19 2006
+++ /export/home/nwc10/p4perl/perl/cop.h	Thu Feb 23 18:01:43 2006
@@ -237,9 +237,10 @@ struct block_sub {
     GV *	dfoutgv;
     AV *	savearray;
     AV *	argarray;
-    I32		olddepth;
-    U8		hasargs;
-    U8		lval;		/* XXX merge lval and hasargs? */
+    int		olddepth:29;
+    unsigned int hasargs:1;
+    unsigned int lval_intro:1;
+    unsigned int lval_inargs:1;
     PAD		*oldcomppad;
     OP *	retop;	/* op to execute on exit from sub */
 };
@@ -262,13 +263,14 @@ struct block_sub {
 
 #define PUSHSUB(cx)							\
 	PUSHSUB_BASE(cx)						\
-	cx->blk_sub.lval = PL_op->op_private &                          \
-	                      (OPpLVAL_INTRO|OPpENTERSUB_INARGS);
+  cx->blk_sub.lval_intro = ((PL_op->op_private & OPpLVAL_INTRO) ? 1 : 0); \
+  cx->blk_sub.lval_inargs = ((PL_op->op_private & OPpENTERSUB_INARGS) ? 1 : 0);
 
 /* variant for use by OP_DBSTATE, where op_private holds hint bits */
 #define PUSHSUB_DB(cx)							\
 	PUSHSUB_BASE(cx)						\
-	cx->blk_sub.lval = 0;
+	cx->blk_sub.lval_intro = 0;					\
+	cx->blk_sub.lval_inargs = 0;
 
 
 #define PUSHFORMAT(cx)							\
==== //depot/perl/pp_ctl.c#527 - /export/home/nwc10/p4perl/perl/pp_ctl.c ====
--- /tmp/tmp.30782.1	Thu Feb 23 19:30:19 2006
+++ /export/home/nwc10/p4perl/perl/pp_ctl.c	Thu Feb 23 18:06:51 2006
@@ -1278,8 +1278,9 @@ Perl_is_lvalue_sub(pTHX)
     const I32 cxix = dopoptosub(cxstack_ix);
     assert(cxix >= 0);  /* We should only be called from inside subs */
 
-    if (cxstack[cxix].blk_sub.lval && CvLVALUE(cxstack[cxix].blk_sub.cv))
-	return cxstack[cxix].blk_sub.lval;
+    if (CvLVALUE(cxstack[cxix].blk_sub.cv))
+	return (cxstack[cxix].blk_sub.lval_intro ? OPpLVAL_INTRO : 0)
+	    | (cxstack[cxix].blk_sub.lval_inargs ? OPpENTERSUB_INARGS : 0);
     else
 	return 0;
 }
==== //depot/perl/pp_hot.c#455 - /export/home/nwc10/p4perl/perl/pp_hot.c ====
--- /tmp/tmp.30782.2	Thu Feb 23 19:30:19 2006
+++ /export/home/nwc10/p4perl/perl/pp_hot.c	Thu Feb 23 18:00:42 2006
@@ -2490,7 +2490,7 @@ PP(pp_leavesublv)
 
     TAINT_NOT;
 
-    if (cx->blk_sub.lval & OPpENTERSUB_INARGS) {
+    if (cx->blk_sub.lval_inargs) {
 	/* We are an argument to a function or grep().
 	 * This kind of lvalueness was legal before lvalue
 	 * subroutines too, so be backward compatible:
@@ -2517,7 +2517,7 @@ PP(pp_leavesublv)
 	    }
 	}
     }
-    else if (cx->blk_sub.lval) {     /* Leave it as it is if we can. */
+    else if (cx->blk_sub.lval_intro) {     /* Leave it as it is if we can. */
 	/* Here we go for robustness, not for speed, so we change all
 	 * the refcounts so the caller gets a live guy. Cannot set
 	 * TEMP, so sv_2mortal is out of question. */



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About