diff options
author | Richard Leach <richardleach@users.noreply.github.com> | 2022-09-09 21:32:09 +0000 |
---|---|---|
committer | Richard Leach <richardleach@users.noreply.github.com> | 2022-09-18 23:50:26 +0100 |
commit | 90dc1489e6280a2f7cd39e74f7be2ec9e556cad7 (patch) | |
tree | 0e400dd6576e8518e8dc72a18c52bac9f3bfcb02 /sv.h | |
parent | 540f4522aa40f6672e5e44976a38fae4b39fa3b8 (diff) | |
download | perl-90dc1489e6280a2f7cd39e74f7be2ec9e556cad7.tar.gz |
sv.c - add SvPVCLEAR_FRESH macro for new PVs with buffer
SvPVCLEAR(tmpstr) is a macro that calls sv_setpv_bufsize(tmpstr,0,0).
If called on a newly minted PV/PVIV/PVNV/PVMG that has a fresh PV
buffer assigned, many of the checks in SvPVCLEAR are unnecessary:
* SvTHINKFIRST - won't be set
* upgrade to SVt_PV - won't be necessary
* SvGROW - we assert that this isn't necessary
It then does some useful, but small actions:
* sets SvCUR(sv, 0);
* sets the last byte in the PV buffer to \0
* sets SvPOK_only_UTF8
* does SvTAINT
Then does a final irrelevant check:
* is tmpstr a PVCV - no it is not
This commit introduces SvPVCLEAR_FRESH as a drop-in replacement
for compatible SVs, that only does the relevant small actions.
Diffstat (limited to 'sv.h')
-rw-r--r-- | sv.h | 18 |
1 files changed, 18 insertions, 0 deletions
@@ -2292,10 +2292,28 @@ existing size, but instead it is the total size C<sv> should be. Ensures that sv is a SVt_PV and that its SvCUR is 0, and that it is properly null terminated. Equivalent to sv_setpvs(""), but more efficient. +=for apidoc Am|char *|SvPVCLEAR_FRESH|SV* sv + +Like SvPVCLEAR, but optimized for newly-minted SVt_PV/PVIV/PVNV/PVMG +that already have a PV buffer allocated, but no SvTHINKFIRST. + =cut */ #define SvPVCLEAR(sv) sv_setpv_bufsize(sv,0,0) +#define SvPVCLEAR_FRESH(sv) \ + STMT_START { \ + assert(SvTYPE(sv) >= SVt_PV); \ + assert(SvTYPE(sv) <= SVt_PVMG); \ + assert(!SvTHINKFIRST(sv)); \ + assert(SvPVX(sv)); \ + SvCUR_set(sv, 0 ); \ + *(SvEND(sv))= '\0'; \ + (void)SvPOK_only_UTF8(sv); \ + SvTAINT(sv); \ + SvPVX(sv); \ + } STMT_END + #define SvSHARE(sv) PL_sharehook(aTHX_ sv) #define SvLOCK(sv) PL_lockhook(aTHX_ sv) #define SvUNLOCK(sv) PL_unlockhook(aTHX_ sv) |