From 544167c5c3aec5993928634c084ae9dd8650be38 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 31 Mar 2015 19:18:49 +0000 Subject: favor more string literals for cold call sites Literal regexps cost over 450 bytes of memory per-site and unnecessary use of them costs memory in places where raw execution speed does not matter. Nowadays, we can rely on String#end_with? (introduced in 1.8.7) for improved readability, too. --- lib/unicorn/socket_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/unicorn/socket_helper.rb') diff --git a/lib/unicorn/socket_helper.rb b/lib/unicorn/socket_helper.rb index a321ddf..812ac53 100644 --- a/lib/unicorn/socket_helper.rb +++ b/lib/unicorn/socket_helper.rb @@ -156,7 +156,7 @@ module Unicorn # returns rfc2732-style (e.g. "[::1]:666") addresses for IPv6 def tcp_name(sock) port, addr = Socket.unpack_sockaddr_in(sock.getsockname) - /:/ =~ addr ? "[#{addr}]:#{port}" : "#{addr}:#{port}" + addr.include?(':') ? "[#{addr}]:#{port}" : "#{addr}:#{port}" end module_function :tcp_name -- cgit v1.2.3-24-ge0c7