summaryrefslogtreecommitdiff
path: root/sv.c
diff options
context:
space:
mode:
authorYves Orton <demerphq@gmail.com>2016-10-19 10:40:29 +0200
committerYves Orton <demerphq@gmail.com>2016-10-19 13:27:59 +0200
commit45661033e6be88d16397139fbd546cb1c7f8cd56 (patch)
tree4faf5988e1671db667cd36d29ae14240f6ec74f8 /sv.c
parent4ac46235a35c3293a6effa2b38b5fe6e37ef7985 (diff)
downloadperl-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.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/sv.c b/sv.c
index dd0b3d456a..e8fab626c7 100644
--- a/sv.c
+++ b/sv.c
@@ -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.