about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2015-04-07 08:09:09 +0000
committerEric Wong <e@80x24.org>2015-04-07 08:09:09 +0000
commit9ae8745eb06cd601d5c1f56eb1e3c4b0678508f8 (patch)
tree33f720029efa674ad3b468f5a2a20a01f027f846 /lib
parentdad99b5ecd93cdf0a514ff9fb51d198f8aebb188 (diff)
downloadyahns-9ae8745eb06cd601d5c1f56eb1e3c4b0678508f8.tar.gz
Literal regexps costs over 400 bytes of memory on x86-64 per-site,
so there's no point in using them to cause bloat at cold call sites
where runtime performance does not matter.
Diffstat (limited to 'lib')
-rw-r--r--lib/yahns/client_expire_tcpi.rb2
-rw-r--r--lib/yahns/config.rb2
-rw-r--r--lib/yahns/socket_helper.rb4
3 files changed, 4 insertions, 4 deletions
diff --git a/lib/yahns/client_expire_tcpi.rb b/lib/yahns/client_expire_tcpi.rb
index 8a89a42..4ca901a 100644
--- a/lib/yahns/client_expire_tcpi.rb
+++ b/lib/yahns/client_expire_tcpi.rb
@@ -38,4 +38,4 @@ module Yahns::ClientExpireTCPI # :nodoc:
   end
 # FreeBSD has "struct tcp_info", too, but does not support all the fields
 # Linux does as of FreeBSD 9 (haven't checked FreeBSD 10, yet).
-end if RUBY_PLATFORM =~ /linux/
+end if RUBY_PLATFORM.include?('linux')
diff --git a/lib/yahns/config.rb b/lib/yahns/config.rb
index e880d92..9db0d59 100644
--- a/lib/yahns/config.rb
+++ b/lib/yahns/config.rb
@@ -236,7 +236,7 @@ class Yahns::Config # :nodoc:
   def canonicalize_tcp(addr, port)
     packed = Socket.pack_sockaddr_in(port, addr)
     port, addr = Socket.unpack_sockaddr_in(packed)
-    /:/ =~ addr ? "[#{addr}]:#{port}" : "#{addr}:#{port}"
+    addr.include?(':') ? "[#{addr}]:#{port}" : "#{addr}:#{port}"
   end
 
   def queue(*args, &block)
diff --git a/lib/yahns/socket_helper.rb b/lib/yahns/socket_helper.rb
index 66df8b0..a74f3f8 100644
--- a/lib/yahns/socket_helper.rb
+++ b/lib/yahns/socket_helper.rb
@@ -8,7 +8,7 @@ module Yahns::SocketHelper # :nodoc:
   def so_reuseport
     if defined?(Socket::SO_REUSEPORT)
       Socket::SO_REUSEPORT
-    elsif RUBY_PLATFORM =~ /linux/
+    elsif RUBY_PLATFORM.include?('linux')
       15 # only tested on x86_64 and i686
     else
       nil
@@ -108,7 +108,7 @@ module Yahns::SocketHelper # :nodoc:
   # 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
 
   # Returns the configuration name of a socket as a string.  sock may