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
}
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;
/* 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;
}
}
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);
}
(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
/* 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 */
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) {
return (char *)s;
}
+/*
+ * Local variables:
+ * c-indentation-style: bsd
+ * c-basic-offset: 4
+ * indent-tabs-mode: t
+ * End:
+ *
+ * vim: shiftwidth=4:
+*/