From 7c123f9da96361fa49e1d9227644d5ee5af4cd0d Mon Sep 17 00:00:00 2001 From: David Mitchell Date: Wed, 12 Jul 2017 14:07:16 +0100 Subject: Make immortal SVs contiguous Ensure that PL_sv_yes, PL_sv_undef, PL_sv_no and PL_sv_zero are allocated adjacently in memory. This allows the SvIMMORTAL() test to be more efficient, and will (in the next commit) allow SvTRUE() to be more efficient. In MULTIPLICITY builds the constraint is already met by virtue of them being adjacent items in the interpreter struct. For non-MULTIPLICITY builds, they were just 4 global vars with no guarantees of where they would be allocated. For this case, PL_sv_undef are deleted as global vars and replaced with a new global var PL_sv_immortals[4], with #define PL_sv_yes (PL_sv_immortals[0]) etc in their place. --- sv.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'sv.c') diff --git a/sv.c b/sv.c index 887c9e7bd8..c17cb92e96 100644 --- a/sv.c +++ b/sv.c @@ -15931,6 +15931,26 @@ Perl_init_constants(pTHX) SvNV_set(&PL_sv_zero, 0); PadnamePV(&PL_padname_const) = (char *)PL_No; + + assert(SvIMMORTAL_INTERP(&PL_sv_yes)); + assert(SvIMMORTAL_INTERP(&PL_sv_undef)); + assert(SvIMMORTAL_INTERP(&PL_sv_no)); + assert(SvIMMORTAL_INTERP(&PL_sv_zero)); + + assert(SvIMMORTAL(&PL_sv_yes)); + assert(SvIMMORTAL(&PL_sv_undef)); + assert(SvIMMORTAL(&PL_sv_no)); + assert(SvIMMORTAL(&PL_sv_zero)); + + assert( SvIMMORTAL_TRUE(&PL_sv_yes)); + assert(!SvIMMORTAL_TRUE(&PL_sv_undef)); + assert(!SvIMMORTAL_TRUE(&PL_sv_no)); + assert(!SvIMMORTAL_TRUE(&PL_sv_zero)); + + assert( SvTRUE_nomg_NN(&PL_sv_yes)); + assert(!SvTRUE_nomg_NN(&PL_sv_undef)); + assert(!SvTRUE_nomg_NN(&PL_sv_no)); + assert(!SvTRUE_nomg_NN(&PL_sv_zero)); } /* -- cgit v1.2.1