Change 33063 by [EMAIL PROTECTED] on 2008/01/24 13:57:20
In struct block_loop, merge itermax and iterlval into a union
lval_max_u, as CXt_LOOP_LAZYIV doesn't use iterlval and the other
LOOP types don't use itermax. This reduces struct block_loop by 1 IV.
As it's the largest component of the unions making up struct context,
this reduces struct context. On ILP32 it will now be 56 bytes, down
from the 64 of 5.10.x, as I've already removed the element 'label'.
Affected files ...
... //depot/perl/cop.h#168 edit
... //depot/perl/pp_ctl.c#673 edit
... //depot/perl/pp_hot.c#564 edit
... //depot/perl/scope.c#220 edit
... //depot/perl/sv.c#1496 edit
Differences ...
==== //depot/perl/cop.h#168 (text) ====
Index: perl/cop.h
--- perl/cop.h#167~33062~ 2008-01-24 05:25:05.000000000 -0800
+++ perl/cop.h 2008-01-24 05:57:20.000000000 -0800
@@ -443,9 +443,14 @@
SV ** itervar;
#endif
SV * itersave;
+ union {
/* (from inspection of source code) for a .. range of strings this is the
current string. */
- SV * iterlval;
+ SV * iterlval;
+ /* (from inspection of source code) for a .. range of numbers this is the
+ maximum value. */
+ IV itermax;
+ } lval_max_u;
union {
/* (from inspection of source code) for a foreach loop this is the array
being iterated over. For a .. range of numbers it's the current value.
@@ -456,19 +461,7 @@
IV itermin;
} ary_min_u;
IV iterix;
- /* (from inspection of source code) for a .. range of numbers this is the
- maximum value. */
- IV itermax;
};
-/* It might be possible to squeeze this structure further. As best I can tell
- itermax and iterlval are never used at the same time, so it might be
possible
- to make them into a union. However, I'm not confident that there are enough
- flag bits/NULLable pointers in this structure alone to encode which is
- active. There is, however, U8 of space free in struct block, which could be
- used. Right now it may not be worth squeezing this structure further, as
it's
- the largest part of struct block, and currently struct block is 64 bytes on
- an ILP32 system, which will give good cache alignment.
-*/
#ifdef USE_ITHREADS
# define CxITERVAR(c) \
@@ -508,7 +501,7 @@
cx->blk_loop.resetsp = s - PL_stack_base; \
cx->blk_loop.my_op = cLOOP; \
PUSHLOOP_OP_NEXT; \
- cx->blk_loop.iterlval = NULL; \
+ cx->blk_loop.lval_max_u.iterlval = NULL; \
cx->blk_loop.ary_min_u.iterary = NULL; \
CX_ITERDATA_SET(cx,NULL);
@@ -516,15 +509,14 @@
cx->blk_loop.resetsp = s - PL_stack_base; \
cx->blk_loop.my_op = cLOOP; \
PUSHLOOP_OP_NEXT; \
- cx->blk_loop.iterlval = NULL; \
+ cx->blk_loop.lval_max_u.iterlval = NULL; \
cx->blk_loop.ary_min_u.iterary = NULL; \
cx->blk_loop.iterix = -1; \
CX_ITERDATA_SET(cx,dat);
#define POPLOOP(cx) \
- if (CxTYPE(cx) == CXt_LOOP_LAZYIV) \
- assert(!cx->blk_loop.iterlval); \
- SvREFCNT_dec(cx->blk_loop.iterlval); \
+ if (CxTYPE(cx) != CXt_LOOP_LAZYIV) \
+ SvREFCNT_dec(cx->blk_loop.lval_max_u.iterlval); \
if (CxITERVAR(cx)) { \
if (SvPADMY(cx->blk_loop.itersave)) { \
SV ** const s_v_p = CxITERVAR(cx); \
==== //depot/perl/pp_ctl.c#673 (text) ====
Index: perl/pp_ctl.c
--- perl/pp_ctl.c#672~33062~ 2008-01-24 05:25:05.000000000 -0800
+++ perl/pp_ctl.c 2008-01-24 05:57:20.000000000 -0800
@@ -1913,20 +1913,19 @@
#endif
DIE(aTHX_ "Range iterator outside integer range");
cx->blk_loop.iterix = SvIV(sv);
- cx->blk_loop.itermax = SvIV(right);
+ cx->blk_loop.lval_max_u.itermax = SvIV(right);
#ifdef DEBUGGING
/* for correct -Dstv display */
cx->blk_oldsp = sp - PL_stack_base;
#endif
}
else {
- cx->blk_loop.iterlval = newSVsv(sv);
- (void) SvPV_force_nolen(cx->blk_loop.iterlval);
+ cx->blk_loop.lval_max_u.iterlval = newSVsv(sv);
+ (void) SvPV_force_nolen(cx->blk_loop.lval_max_u.iterlval);
(void) SvPV_nolen_const(right);
}
}
else if (PL_op->op_private & OPpITER_REVERSED) {
- cx->blk_loop.itermax = 0xDEADBEEF;
cx->blk_loop.iterix = AvFILL(cx->blk_loop.ary_min_u.iterary) + 1;
}
==== //depot/perl/pp_hot.c#564 (text) ====
Index: perl/pp_hot.c
--- perl/pp_hot.c#563~33062~ 2008-01-24 05:25:05.000000000 -0800
+++ perl/pp_hot.c 2008-01-24 05:57:20.000000000 -0800
@@ -1917,7 +1917,7 @@
/* iterate ($min .. $max) */
if (CxTYPE(cx) != CXt_LOOP_LAZYIV) {
/* string increment */
- register SV* cur = cx->blk_loop.iterlval;
+ register SV* cur = cx->blk_loop.lval_max_u.iterlval;
STRLEN maxlen = 0;
const char *max =
SvOK((SV*)av) ?
@@ -1945,8 +1945,7 @@
RETPUSHNO;
}
/* integer increment */
- assert(!cx->blk_loop.iterlval);
- if (cx->blk_loop.iterix > cx->blk_loop.itermax)
+ if (cx->blk_loop.iterix > cx->blk_loop.lval_max_u.itermax)
RETPUSHNO;
/* don't risk potential race */
@@ -1966,10 +1965,10 @@
/* Handle end of range at IV_MAX */
if ((cx->blk_loop.iterix == IV_MIN) &&
- (cx->blk_loop.itermax == IV_MAX))
+ (cx->blk_loop.lval_max_u.itermax == IV_MAX))
{
cx->blk_loop.iterix++;
- cx->blk_loop.itermax++;
+ cx->blk_loop.lval_max_u.itermax++;
}
RETPUSHYES;
@@ -2014,7 +2013,7 @@
else
sv = &PL_sv_undef;
if (av != PL_curstack && sv == &PL_sv_undef) {
- SV *lv = cx->blk_loop.iterlval;
+ SV *lv = cx->blk_loop.lval_max_u.iterlval;
if (lv && SvREFCNT(lv) > 1) {
SvREFCNT_dec(lv);
lv = NULL;
@@ -2022,7 +2021,7 @@
if (lv)
SvREFCNT_dec(LvTARG(lv));
else {
- lv = cx->blk_loop.iterlval = newSV_type(SVt_PVLV);
+ lv = cx->blk_loop.lval_max_u.iterlval = newSV_type(SVt_PVLV);
LvTYPE(lv) = 'y';
sv_magic(lv, NULL, PERL_MAGIC_defelem, NULL, 0);
}
==== //depot/perl/scope.c#220 (text) ====
Index: perl/scope.c
--- perl/scope.c#219~33062~ 2008-01-24 05:25:05.000000000 -0800
+++ perl/scope.c 2008-01-24 05:57:20.000000000 -0800
@@ -1104,7 +1104,7 @@
PerlIO_printf(Perl_debug_log, "BLK_LOOP.ITERSAVE = 0x%"UVxf"\n",
PTR2UV(cx->blk_loop.itersave));
PerlIO_printf(Perl_debug_log, "BLK_LOOP.ITERLVAL = 0x%"UVxf"\n",
- PTR2UV(cx->blk_loop.iterlval));
+ PTR2UV(cx->blk_loop.lval_max_u.iterlval));
break;
case CXt_SUBST:
==== //depot/perl/sv.c#1496 (text) ====
Index: perl/sv.c
--- perl/sv.c#1495~33062~ 2008-01-24 05:25:05.000000000 -0800
+++ perl/sv.c 2008-01-24 05:57:20.000000000 -0800
@@ -10557,8 +10557,9 @@
ncx->blk_loop.oldcomppad);
ncx->blk_loop.itersave = sv_dup_inc(ncx->blk_loop.itersave,
param);
- ncx->blk_loop.iterlval = sv_dup_inc(ncx->blk_loop.iterlval,
- param);
+ if (CxTYPE(ncx) != CXt_LOOP_LAZYIV)
+ ncx->blk_loop.lval_max_u.iterlval
+ = sv_dup_inc(ncx->blk_loop.lval_max_u.iterlval, param);
break;
case CXt_FORMAT:
ncx->blk_format.cv = cv_dup(ncx->blk_format.cv, param);
End of Patch.