From 6ea71159e2557eca51d2388f07ab552c69a44dd7 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 8 Jul 2010 05:33:49 +0000 Subject: prefer "[]" to "first"/"last" where possible "[]" is slightly faster under Ruby 1.9 (but slightly slower under 1.8). (cherry picked from commit 5ece8c1c33f10e6496dfe5ae1d0d368293278d2d) --- lib/unicorn.rb | 12 ++++++------ lib/unicorn/http_request.rb | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/unicorn.rb b/lib/unicorn.rb index a7b0646..e60dd61 100644 --- a/lib/unicorn.rb +++ b/lib/unicorn.rb @@ -482,8 +482,8 @@ module Unicorn # Wake up every second anyways to run murder_lazy_workers def master_sleep(sec) begin - IO.select([ SELF_PIPE.first ], nil, nil, sec) or return - SELF_PIPE.first.read_nonblock(Const::CHUNK_SIZE, HttpRequest::BUF) + IO.select([ SELF_PIPE[0] ], nil, nil, sec) or return + SELF_PIPE[0].read_nonblock(Const::CHUNK_SIZE, HttpRequest::BUF) rescue Errno::EAGAIN, Errno::EINTR break end while true @@ -491,7 +491,7 @@ module Unicorn def awaken_master begin - SELF_PIPE.last.write_nonblock('.') # wakeup master process from select + SELF_PIPE[1].write_nonblock('.') # wakeup master process from select rescue Errno::EAGAIN, Errno::EINTR # pipe is full, master should wake up anyways retry @@ -635,7 +635,7 @@ module Unicorn client.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) response = app.call(env = REQUEST.read(client)) - if 100 == response.first.to_i + if 100 == response[0].to_i client.write(Const::EXPECT_100_RESPONSE) env.delete(Const::HTTP_EXPECT) response = app.call(env) @@ -684,7 +684,7 @@ module Unicorn ready = LISTENERS # closing anything we IO.select on will raise EBADF - trap(:USR1) { nr = -65536; SELF_PIPE.first.close rescue nil } + trap(:USR1) { nr = -65536; SELF_PIPE[0].close rescue nil } trap(:QUIT) { alive = nil; LISTENERS.each { |s| s.close rescue nil } } [:TERM, :INT].each { |sig| trap(sig) { exit!(0) } } # instant shutdown logger.info "worker=#{worker.nr} ready" @@ -725,7 +725,7 @@ module Unicorn begin # timeout used so we can detect parent death: ret = IO.select(LISTENERS, nil, SELF_PIPE, timeout) or redo - ready = ret.first + ready = ret[0] rescue Errno::EINTR ready = LISTENERS rescue Errno::EBADF diff --git a/lib/unicorn/http_request.rb b/lib/unicorn/http_request.rb index 65b09fa..8c369cf 100644 --- a/lib/unicorn/http_request.rb +++ b/lib/unicorn/http_request.rb @@ -53,7 +53,7 @@ module Unicorn # that client may be a proxy, gateway, or other intermediary # acting on behalf of the actual source client." REQ[Const::REMOTE_ADDR] = - TCPSocket === socket ? socket.peeraddr.last : LOCALHOST + TCPSocket === socket ? socket.peeraddr[-1] : LOCALHOST # short circuit the common case with small GET requests first if PARSER.headers(REQ, socket.readpartial(Const::CHUNK_SIZE, BUF)).nil? -- cgit v1.2.3-24-ge0c7