summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2009-10-15 16:26:51 +0100
committerNicholas Clark <nick@ccl4.org>2009-10-15 17:12:59 +0100
commit8dbe7cf704038839ade17963855cf8bfad0c30a3 (patch)
treeb98bf57b99fa95612f46e891838b5225659c938a /ext
parentdc57de01240c08cc88678a29fcb4e2d5f23efa66 (diff)
downloadperl-8dbe7cf704038839ade17963855cf8bfad0c30a3.tar.gz
In strftime(), save a malloc()/free() by using sv_usepvn_flags().
Diffstat (limited to 'ext')
-rw-r--r--ext/POSIX/POSIX.xs8
1 files changed, 6 insertions, 2 deletions
diff --git a/ext/POSIX/POSIX.xs b/ext/POSIX/POSIX.xs
index b3a64a7a28..85723675af 100644
--- a/ext/POSIX/POSIX.xs
+++ b/ext/POSIX/POSIX.xs
@@ -1795,8 +1795,12 @@ strftime(fmt, sec, min, hour, mday, mon, year, wday = -1, yday = -1, isdst = -1)
{
char *buf = my_strftime(SvPV_nolen(fmt), sec, min, hour, mday, mon, year, wday, yday, isdst);
if (buf) {
- ST(0) = newSVpvn_flags(buf, strlen(buf), SVs_TEMP | SvUTF8(fmt));
- Safefree(buf);
+ SV *const sv = sv_newmortal();
+ sv_usepvn_flags(sv, buf, strlen(buf), SV_HAS_TRAILING_NUL);
+ if (SvUTF8(fmt)) {
+ SvUTF8_on(sv);
+ }
+ ST(0) = sv;
}
}