From 4c4d047892beb9432a38835e1b9a9b7ed9800047 Mon Sep 17 00:00:00 2001 From: bulk88 Date: Tue, 22 Apr 2025 14:21:11 -0400 Subject: [PATCH 1/2] add #define PERL_NO_GET_CONTEXT to stop the Perl_get_context() calls -Perl_get_context() is a slow TLS getter func, and its only for src code compat with abandoned ancient pre-ithreads XS modules. --- COW.xs | 1 + 1 file changed, 1 insertion(+) diff --git a/COW.xs b/COW.xs index 08f389f..ad41ee0 100644 --- a/COW.xs +++ b/COW.xs @@ -7,6 +7,7 @@ * */ +#define PERL_NO_GET_CONTEXT #include #include #include From 7be7c3f5ed0ca8a58b515a07c751c14e96fc4a30 Mon Sep 17 00:00:00 2001 From: bulk88 Date: Tue, 22 Apr 2025 14:53:43 -0400 Subject: [PATCH 2/2] add newCONSTSUB_flags() so PP code can constant fold --- COW.xs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/COW.xs b/COW.xs index ad41ee0..6f9985e 100644 --- a/COW.xs +++ b/COW.xs @@ -22,10 +22,17 @@ /* CowREFCNT is incorrect on Perl < 5.32 */ #define myCowREFCNT(sv) ((SvLEN(sv)>0) ? CowREFCNT(sv) : 0) +#ifndef newCONSTSUB_flags +# define newCONSTSUB_flags(_hv, _nm, _len, _flg, _sv) newCONSTSUB(_hv, _nm, _sv) +#endif + MODULE = B__COW PACKAGE = B::COW PROTOTYPES: DISABLE +# Converted to newCONSTSUB_flags() +#if 0 + SV* can_cow() CODE: @@ -39,6 +46,8 @@ CODE: OUTPUT: RETVAL +#endif + SV* is_cow(sv) SV *sv; @@ -70,6 +79,10 @@ CODE: OUTPUT: RETVAL + +# Converted to newCONSTSUB_flags() +#if 0 + SV* cowrefcnt_max() CODE: @@ -82,3 +95,25 @@ CODE: } OUTPUT: RETVAL + +#endif + +BOOT: +{ + HV* stash; /* get HV* stash from this XSUB's CV*, faster than gv_stashpvs() */ + if (CvNAMED(cv)) /* EU::ParseXS's ALIAS:/XSANY overwrites C auto var cv */ + stash = CvSTASH(cv); /* but this module doesn't use the ALIAS: feature */ + else { + GV* gv = CvGV(cv); /* fn call */ + stash = GvSTASH(gv); + } +#if !B_CAN_COW + newCONSTSUB_flags( stash, "cowrefcnt_max", sizeof("cowrefcnt_max")-1, 0, + &PL_sv_undef); + newCONSTSUB_flags( stash, "can_cow", sizeof("can_cow")-1, 0, &PL_sv_no); +#else + newCONSTSUB_flags( stash, "cowrefcnt_max", sizeof("cowrefcnt_max")-1, 0, + newSViv(SV_COW_REFCNT_MAX)); + newCONSTSUB_flags( stash, "can_cow", sizeof("can_cow")-1, 0, &PL_sv_yes); +#endif +}