From ad7e388f65d0053a4f28762a1bcd2c95e11a68c9 Mon Sep 17 00:00:00 2001 From: Karl Williamson Date: Sat, 7 Nov 2020 07:21:52 -0700 Subject: [PATCH 1/2] Make tr/// SV compiled components ReadOnly This could trigger some optimisations, and makes it clear to maintainers that they do not get modified. --- op.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/op.c b/op.c index 421387ed107b..8ea2e053653e 100644 --- a/op.c +++ b/op.c @@ -7909,6 +7909,7 @@ S_pmtrans(pTHX_ OP *o, OP *expr, OP *repl) || r_map[len-1] == TR_SPECIAL_HANDLING)))) { SV* r_map_sv; + SV* temp_sv; /* A UTF-8 op is generated, indicated by this flag. This op is an * sv_op */ @@ -7920,19 +7921,26 @@ S_pmtrans(pTHX_ OP *o, OP *expr, OP *repl) /* The inversion map is pushed; first the list. */ invmap = MUTABLE_AV(newAV()); + + SvREADONLY_on(t_invlist); av_push(invmap, t_invlist); /* 2nd is the mapping */ r_map_sv = newSVpvn((char *) r_map, len * sizeof(UV)); + SvREADONLY_on(r_map_sv); av_push(invmap, r_map_sv); /* 3rd is the max possible expansion factor */ - av_push(invmap, newSVnv(max_expansion)); + temp_sv = newSVnv(max_expansion); + SvREADONLY_on(temp_sv); + av_push(invmap, temp_sv); /* Characters that are in the search list, but not in the replacement * list are mapped to the final character in the replacement list */ if (! del && r_count < t_count) { - av_push(invmap, newSVuv(final_map)); + temp_sv = newSVuv(final_map); + SvREADONLY_on(temp_sv); + av_push(invmap, temp_sv); } #ifdef USE_ITHREADS From 96db8326826e0fd376a71600700e3cd534021094 Mon Sep 17 00:00:00 2001 From: Karl Williamson Date: Sat, 7 Nov 2020 07:23:42 -0700 Subject: [PATCH 2/2] Make inversion list internals available to B They are needed because the optree now refers to them --- ext/B/B.xs | 1 + invlist_inline.h | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/ext/B/B.xs b/ext/B/B.xs index e6e3fb830968..e89118502679 100644 --- a/ext/B/B.xs +++ b/ext/B/B.xs @@ -10,6 +10,7 @@ #define PERL_NO_GET_CONTEXT #define PERL_EXT #include "EXTERN.h" +#define PERL_IN_B_XS #include "perl.h" #include "XSUB.h" diff --git a/invlist_inline.h b/invlist_inline.h index f6ac81953355..1aec16a89a8a 100644 --- a/invlist_inline.h +++ b/invlist_inline.h @@ -15,7 +15,8 @@ || defined(PERL_IN_TOKE_C) \ || defined(PERL_IN_PP_C) \ || defined(PERL_IN_OP_C) \ - || defined(PERL_IN_DOOP_C) + || defined(PERL_IN_DOOP_C) \ + || defined(PERL_IN_B_XS) /* An element is in an inversion list iff its index is even numbered: 0, 2, 4, * etc */