From: Nicholas Clark Date: Mon, 18 Apr 2005 21:58:22 +0000 (+0000) Subject: SvPV_renew also calls SvLEN_set X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1da4ca5ff65374ad6965719e5eb33e3027a745a7;p=p5sagit%2Fp5-mst-13.2.git SvPV_renew also calls SvLEN_set Add SvPV_shrink_to_cur(sv) to call SvPV_renew with SvCUR(sv)+1. For Ponie this can be a single call into the PMC p4raw-id: //depot/perl@24245 --- diff --git a/pp_hot.c b/pp_hot.c index 64c4fec..825a862 100644 --- a/pp_hot.c +++ b/pp_hot.c @@ -1624,8 +1624,7 @@ Perl_do_readline(pTHX) } if (gimme == G_ARRAY) { if (SvLEN(sv) - SvCUR(sv) > 20) { - SvLEN_set(sv, SvCUR(sv)+1); - SvPV_renew(sv, SvLEN(sv)); + SvPV_shrink_to_cur(sv); } sv = sv_2mortal(NEWSV(58, 80)); continue; @@ -1634,8 +1633,7 @@ Perl_do_readline(pTHX) /* try to reclaim a bit of scalar space (only on 1st alloc) */ const STRLEN new_len = SvCUR(sv) < 60 ? 80 : SvCUR(sv)+40; /* allow some slop */ - SvLEN_set(sv, new_len); - SvPV_renew(sv, SvLEN(sv)); + SvPV_renew(sv, new_len); } RETURN; } diff --git a/pp_sys.c b/pp_sys.c index 9d31e81..300ea6d 100644 --- a/pp_sys.c +++ b/pp_sys.c @@ -361,8 +361,7 @@ PP(pp_backtick) } XPUSHs(sv_2mortal(sv)); if (SvLEN(sv) - SvCUR(sv) > 20) { - SvLEN_set(sv, SvCUR(sv)+1); - SvPV_renew(sv, SvLEN(sv)); + SvPV_shrink_to_cur(sv); } SvTAINTED_on(sv); } diff --git a/sv.h b/sv.h index 511b547..b90d209 100644 --- a/sv.h +++ b/sv.h @@ -794,8 +794,16 @@ in gv.h: */ (SvCUR(sv) = (val) - SvPVX(sv)); } STMT_END #define SvPV_renew(sv,n) \ - (SvPV_set((sv), (MEM_WRAP_CHECK_(n,char) \ - (char*)saferealloc((Malloc_t)SvPVX(sv),(MEM_SIZE)((n)))))) + STMT_START { SvLEN_set(sv, n); \ + SvPV_set((sv), (MEM_WRAP_CHECK_(n,char) \ + (char*)saferealloc((Malloc_t)SvPVX(sv), \ + (MEM_SIZE)((n))))); \ + } STMT_END + +#define SvPV_shrink_to_cur(sv) STMT_START { \ + const STRLEN _lEnGtH = SvCUR(sv) + 1; \ + SvPV_renew(sv, _lEnGtH); \ + } STMT_END #define BmRARE(sv) ((XPVBM*) SvANY(sv))->xbm_rare #define BmUSEFUL(sv) ((XPVBM*) SvANY(sv))->xbm_useful diff --git a/toke.c b/toke.c index 5518078..352254f 100644 --- a/toke.c +++ b/toke.c @@ -1825,8 +1825,7 @@ S_scan_const(pTHX_ char *start) /* shrink the sv if we allocated more than we used */ if (SvCUR(sv) + 5 < SvLEN(sv)) { - SvLEN_set(sv, SvCUR(sv) + 1); - SvPV_renew(sv, SvLEN(sv)); + SvPV_shrink_to_cur(sv); } /* return the substring (via yylval) only if we parsed anything */ @@ -9603,8 +9602,7 @@ S_scan_heredoc(pTHX_ register char *s) retval: PL_multi_end = CopLINE(PL_curcop); if (SvCUR(tmpstr) + 5 < SvLEN(tmpstr)) { - SvLEN_set(tmpstr, SvCUR(tmpstr) + 1); - SvPV_renew(tmpstr, SvLEN(tmpstr)); + SvPV_shrink_to_cur(tmpstr); } SvREFCNT_dec(herewas); if (!IN_BYTES) { @@ -10975,3 +10973,12 @@ Perl_scan_vstring(pTHX_ const char *s, SV *sv) return (char *)s; } +/* + * Local variables: + * c-indentation-style: bsd + * c-basic-offset: 4 + * indent-tabs-mode: t + * End: + * + * vim: shiftwidth=4: +*/