diff options
author | Eric Wong <e@80x24.org> | 2015-03-31 19:18:49 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2015-04-07 07:56:01 +0000 |
commit | 544167c5c3aec5993928634c084ae9dd8650be38 (patch) | |
tree | 48e86d49683bb4ccb3449c3d4279439e090b65a2 /lib/unicorn | |
parent | 7d10e85c045a80df260dee1a6717483c5037ef56 (diff) | |
download | unicorn-544167c5c3aec5993928634c084ae9dd8650be38.tar.gz |
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.
Diffstat (limited to 'lib/unicorn')
-rw-r--r-- | lib/unicorn/configurator.rb | 4 | ||||
-rw-r--r-- | lib/unicorn/http_server.rb | 2 | ||||
-rw-r--r-- | lib/unicorn/socket_helper.rb | 2 |
3 files changed, 4 insertions, 4 deletions
diff --git a/lib/unicorn/configurator.rb b/lib/unicorn/configurator.rb index 69b4644..32e49c1 100644 --- a/lib/unicorn/configurator.rb +++ b/lib/unicorn/configurator.rb @@ -586,7 +586,7 @@ private 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 set_path(var, path) #:nodoc: @@ -642,7 +642,7 @@ private raise ArgumentError, "rackup file (#{ru}) not readable" # it could be a .rb file, too, we don't parse those manually - ru =~ /\.ru\z/ or return + ru.end_with?('.ru') or return /^#\\(.*)/ =~ File.read(ru) or return RACKUP[:optparse].parse!($1.split(/\s+/)) diff --git a/lib/unicorn/http_server.rb b/lib/unicorn/http_server.rb index 77345d2..a726c91 100644 --- a/lib/unicorn/http_server.rb +++ b/lib/unicorn/http_server.rb @@ -186,7 +186,7 @@ class Unicorn::HttpServer if path if x = valid_pid?(path) return path if pid && path == pid && x == $$ - if x == reexec_pid && pid =~ /\.oldbin\z/ + if x == reexec_pid && pid.end_with?('.oldbin') logger.warn("will not set pid=#{path} while reexec-ed "\ "child is running PID:#{x}") return 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 |