From 61c20aae4b2b2a142bb368219ed3a4b218d714a8 Mon Sep 17 00:00:00 2001 From: Igor Sysoev Date: Wed, 28 Jun 2017 09:33:35 +0300 Subject: Small optimization in nxt_sockaddr_text(). --- src/nxt_sockaddr.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) (limited to 'src/nxt_sockaddr.c') diff --git a/src/nxt_sockaddr.c b/src/nxt_sockaddr.c index 4119fe8c..79d01b8a 100644 --- a/src/nxt_sockaddr.c +++ b/src/nxt_sockaddr.c @@ -193,17 +193,17 @@ nxt_sockaddr_text(nxt_sockaddr_t *sa) u_char *p, *start, *end, *octet; uint32_t port; + offset = offsetof(nxt_sockaddr_t, u) + sa->socklen; + sa->start = offset; + + start = nxt_pointer_to(sa, offset); end = nxt_pointer_to(sa, sa->sockaddr_size); switch (sa->u.sockaddr.sa_family) { case AF_INET: - offset = offsetof(nxt_sockaddr_t, u) + sizeof(struct sockaddr_in); - - sa->start = offset; sa->address_start = offset; - start = nxt_pointer_to(sa, offset); octet = (u_char *) &sa->u.sockaddr_in.sin_addr; p = nxt_sprintf(start, end, "%ud.%ud.%ud.%ud", @@ -219,14 +219,9 @@ nxt_sockaddr_text(nxt_sockaddr_t *sa) #if (NXT_INET6) case AF_INET6: - offset = offsetof(nxt_sockaddr_t, u) + sizeof(struct sockaddr_in6); - - sa->start = offset; sa->address_start = offset + 1; - start = nxt_pointer_to(sa, offset); p = start; - *p++ = '['; p = nxt_inet6_ntop(sa->u.sockaddr_in6.sin6_addr.s6_addr, p, end); @@ -245,12 +240,8 @@ nxt_sockaddr_text(nxt_sockaddr_t *sa) #if (NXT_HAVE_UNIX_DOMAIN) case AF_UNIX: - offset = offsetof(nxt_sockaddr_t, u) + sa->socklen; - - sa->start = offset; sa->address_start = offset; - start = nxt_pointer_to(sa, offset); p = (u_char *) sa->u.sockaddr_un.sun_path; #if (NXT_LINUX) -- cgit