From: Eric Wong <e@80x24.org>
To: unicorn-public@bogomips.org
Subject: [PATCH] reduce method calls with String#start_with?
Date: Wed, 28 Jun 2017 00:19:02 +0000 [thread overview]
Message-ID: <20170628001902.4356-1-e@80x24.org> (raw)
These three cold call sites instruction sequence size by a few
hundred bytes combined since we no longer support Ruby 1.8.6.
The "?/" shorthand is esoteric and no longer avoids allocation
in Ruby 1.9+ (not that this is hot code).
---
lib/unicorn/configurator.rb | 2 +-
lib/unicorn/http_server.rb | 2 +-
lib/unicorn/socket_helper.rb | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/lib/unicorn/configurator.rb b/lib/unicorn/configurator.rb
index 7fb9030f..f34d38b8 100644
--- a/lib/unicorn/configurator.rb
+++ b/lib/unicorn/configurator.rb
@@ -587,7 +587,7 @@ def working_directory(path)
# just let chdir raise errors
path = File.expand_path(path)
if config_file &&
- config_file[0] != ?/ &&
+ ! config_file.start_with?('/') &&
! File.readable?("#{path}/#{config_file}")
raise ArgumentError,
"config_file=#{config_file} would not be accessible in" \
diff --git a/lib/unicorn/http_server.rb b/lib/unicorn/http_server.rb
index 3827f2e9..f33aa252 100644
--- a/lib/unicorn/http_server.rb
+++ b/lib/unicorn/http_server.rb
@@ -148,7 +148,7 @@ def start
def listeners=(listeners)
cur_names, dead_names = [], []
listener_names.each do |name|
- if ?/ == name[0]
+ if name.start_with?('/')
# mark unlinked sockets as dead so we can rebind them
(File.socket?(name) ? cur_names : dead_names) << name
else
diff --git a/lib/unicorn/socket_helper.rb b/lib/unicorn/socket_helper.rb
index f52dde2d..9e672d97 100644
--- a/lib/unicorn/socket_helper.rb
+++ b/lib/unicorn/socket_helper.rb
@@ -116,7 +116,7 @@ def log_buffer_sizes(sock, pfx = '')
def bind_listen(address = '0.0.0.0:8080', opt = {})
return address unless String === address
- sock = if address[0] == ?/
+ sock = if address.start_with?('/')
if File.exist?(address)
if File.socket?(address)
begin
--
EW
reply other threads:[~2017-06-28 0:19 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://yhbt.net/unicorn/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170628001902.4356-1-e@80x24.org \
--to=e@80x24.org \
--cc=unicorn-public@bogomips.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
http://yhbt.net/unicorn.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).