From b45a10818e56f8db8d692c5b5abe8bae3a6e0586 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Tue, 1 May 2012 14:55:51 +0200 Subject: [PATCH] udp: slightly optimize address family property --- src/udp_wrap.cc | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/udp_wrap.cc b/src/udp_wrap.cc index 38b08a25d2..244bc67165 100644 --- a/src/udp_wrap.cc +++ b/src/udp_wrap.cc @@ -68,6 +68,8 @@ Local AddressToJS(const sockaddr* addr); static Persistent address_sym; static Persistent port_sym; static Persistent family_sym; +static Persistent ipv4_sym; +static Persistent ipv6_sym; static Persistent buffer_sym; static Persistent oncomplete_sym; static Persistent onmessage_sym; @@ -136,6 +138,8 @@ void UDPWrap::Initialize(Handle target) { oncomplete_sym = NODE_PSYMBOL("oncomplete"); onmessage_sym = NODE_PSYMBOL("onmessage"); family_sym = NODE_PSYMBOL("family"); + ipv4_sym = NODE_PSYMBOL("IPv4"); + ipv6_sym = NODE_PSYMBOL("IPv6"); Local t = FunctionTemplate::New(New); t->InstanceTemplate()->SetInternalFieldCount(1); @@ -449,7 +453,6 @@ Local AddressToJS(const sockaddr* addr) { const sockaddr_in *a4; const sockaddr_in6 *a6; int port; - const char *family_name; Local info = Object::New(); @@ -458,20 +461,18 @@ Local AddressToJS(const sockaddr* addr) { a6 = reinterpret_cast(addr); uv_inet_ntop(AF_INET6, &a6->sin6_addr, ip, sizeof ip); port = ntohs(a6->sin6_port); - family_name = "IPv6"; info->Set(address_sym, String::New(ip)); - info->Set(family_sym, String::New(family_name)); info->Set(port_sym, Integer::New(port)); + info->Set(family_sym, ipv6_sym); break; case AF_INET: a4 = reinterpret_cast(addr); uv_inet_ntop(AF_INET, &a4->sin_addr, ip, sizeof ip); port = ntohs(a4->sin_port); - family_name = "IPv4"; info->Set(address_sym, String::New(ip)); - info->Set(family_sym, String::New(family_name)); info->Set(port_sym, Integer::New(port)); + info->Set(family_sym, ipv4_sym); break; default: