diff options
-rw-r--r-- | pp_hot.c | 6 | ||||
-rw-r--r-- | pp_sys.c | 3 | ||||
-rw-r--r-- | sv.h | 12 | ||||
-rw-r--r-- | toke.c | 15 |
4 files changed, 24 insertions, 12 deletions
@@ -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; } @@ -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); } @@ -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 @@ -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: +*/ |