From: Nicholas Clark Date: Thu, 15 Oct 2009 15:26:51 +0000 (+0100) Subject: In strftime(), save a malloc()/free() by using sv_usepvn_flags(). X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8dbe7cf704038839ade17963855cf8bfad0c30a3;p=p5sagit%2Fp5-mst-13.2.git In strftime(), save a malloc()/free() by using sv_usepvn_flags(). --- diff --git a/ext/POSIX/POSIX.xs b/ext/POSIX/POSIX.xs index b3a64a7..8572367 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; } }