summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pp_hot.c6
-rw-r--r--pp_sys.c3
-rw-r--r--sv.h12
-rw-r--r--toke.c15
4 files changed, 24 insertions, 12 deletions
diff --git a/pp_hot.c b/pp_hot.c
index 64c4fecf7f..825a862b24 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 9d31e81b5b..300ea6d94c 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 511b547c75..b90d209c5f 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 55180788bf..352254f0ab 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:
+*/