From 23933b71b68b2a941ad96656d331a8c2775288cc Mon Sep 17 00:00:00 2001 From: Nicholas Clark Date: Thu, 21 Oct 2010 17:58:42 +0100 Subject: [PATCH] Sys::Hostname::ghname should use newSVpv(s, 0), not newSVpvn(s, strlen(s)) Whilst functionally identical, the latter will produce more object code. Also, avoid the strlen() entirely for the case of HAS_PHOSTNAME, where we know the length. --- ext/Sys-Hostname/Hostname.xs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/ext/Sys-Hostname/Hostname.xs b/ext/Sys-Hostname/Hostname.xs index 23ecd69..3ec72f7 100644 --- a/ext/Sys-Hostname/Hostname.xs +++ b/ext/Sys-Hostname/Hostname.xs @@ -35,7 +35,7 @@ ghname() { char tmps[MAXHOSTNAMELEN]; retval = PerlSock_gethostname(tmps, sizeof(tmps)); - sv = newSVpvn(tmps, strlen(tmps)); + sv = newSVpv(tmps, 0); } #else # ifdef HAS_PHOSTNAME @@ -53,9 +53,8 @@ ghname() *p++ = c; } PerlProc_pclose(io); - *p = '\0'; retval = 0; - sv = newSVpvn(tmps, strlen(tmps)); + sv = newSVpvn(tmps, p - tmps); } # else # ifdef HAS_UNAME @@ -63,7 +62,7 @@ ghname() struct utsname u; if (PerlEnv_uname(&u) == -1) goto check_out; - sv = newSVpvn(u.nodename, strlen(u.nodename)); + sv = newSVpv(u.nodename, 0); retval = 0; } # endif -- 2.7.4