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/configurator.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/unicorn/configurator.rb') 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+/)) -- cgit v1.2.3-24-ge0c7