summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-07-08 05:33:49 +0000
committerEric Wong <normalperson@yhbt.net>2010-07-08 05:40:47 +0000
commit6ea71159e2557eca51d2388f07ab552c69a44dd7 (patch)
tree99164e633ebf8eccf57e724c8a1a82702bbfca93
parent4fa17dfb4adef0945d73e692147a3302b8dd9b74 (diff)
"[]" is slightly faster under Ruby 1.9 (but slightly
slower under 1.8).
(cherry picked from commit 5ece8c1c33f10e6496dfe5ae1d0d368293278d2d)
-rw-r--r--lib/unicorn.rb12
-rw-r--r--lib/unicorn/http_request.rb2
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?