diff options
author | Yves Orton <demerphq@gmail.com> | 2016-10-19 10:40:29 +0200 |
---|---|---|
committer | Yves Orton <demerphq@gmail.com> | 2016-10-19 13:27:59 +0200 |
commit | 45661033e6be88d16397139fbd546cb1c7f8cd56 (patch) | |
tree | 4faf5988e1671db667cd36d29ae14240f6ec74f8 /sv.c | |
parent | 4ac46235a35c3293a6effa2b38b5fe6e37ef7985 (diff) | |
download | perl-45661033e6be88d16397139fbd546cb1c7f8cd56.tar.gz |
sv.c: add sv_setpv_bufsize() and SvPVCLEAR()
The first can be used to wrap several SVPV steps into
a single sub, and a wrapper macro which is the equivalent
of
$s= "";
but is optimized in various ways.
Diffstat (limited to 'sv.c')
-rw-r--r-- | sv.c | 29 |
1 files changed, 29 insertions, 0 deletions
@@ -4875,6 +4875,35 @@ Perl_sv_setsv_cow(pTHX_ SV *dstr, SV *sstr) #endif /* +=for apidoc sv_setpv_bufsize + +Sets the SV to be a string of cur bytes length, with at least +len bytes available. Ensures that there is a null byte at SvEND. +Returns a char * pointer to the SvPV buffer. + +=cut +*/ + +char * +Perl_sv_setpv_bufsize(pTHX_ SV *const sv, const STRLEN cur, const STRLEN len) +{ + char *pv; + + PERL_ARGS_ASSERT_SV_SETPV_BUFSIZE; + + SV_CHECK_THINKFIRST_COW_DROP(sv); + SvUPGRADE(sv, SVt_PV); + pv = SvGROW(sv, len + 1); + SvCUR_set(sv, cur); + *(SvEND(sv))= '\0'; + (void)SvPOK_only_UTF8(sv); /* validate pointer */ + + SvTAINT(sv); + if (SvTYPE(sv) == SVt_PVCV) CvAUTOLOAD_off(sv); + return pv; +} + +/* =for apidoc sv_setpvn Copies a string (possibly containing embedded C<NUL> characters) into an SV. |