about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2015-11-21 08:52:29 +0000
committerEric Wong <e@80x24.org>2015-11-21 08:55:00 +0000
commita5d88662a519406eea6f180a010af8ef829464e7 (patch)
tree77034a0a236921b1ab2c6c237ac92a016de49c10 /lib
parent9e7fb4e9b5d97cc75892c8faaea46444d438eb61 (diff)
downloadrainbows-a5d88662a519406eea6f180a010af8ef829464e7.tar.gz
unicorn 5 will only support Ruby 1.9.3 and later, so remove
some checks for Hash#compare_by_identity and IO.copy_stream
which we know exist in Ruby 1.9.

Favor &:sym proc dispatch to avoid unnecessary captures and
bytecode size increases, too.

Finally, ensure we fail fast by converting some literal
hashes to use non-arrow syntax for symbolic keys.
Diffstat (limited to 'lib')
-rw-r--r--lib/rainbows.rb5
-rw-r--r--lib/rainbows/configurator.rb16
-rw-r--r--lib/rainbows/coolio.rb9
-rw-r--r--lib/rainbows/coolio/heartbeat.rb2
-rw-r--r--lib/rainbows/epoll/client.rb5
-rw-r--r--lib/rainbows/fiber/base.rb2
-rw-r--r--lib/rainbows/writer_thread_pool.rb4
-rw-r--r--lib/rainbows/xepoll_thread_pool/client.rb3
-rw-r--r--lib/rainbows/xepoll_thread_spawn/client.rb3
9 files changed, 20 insertions, 29 deletions
diff --git a/lib/rainbows.rb b/lib/rainbows.rb
index f23b387..6e7e4f2 100644
--- a/lib/rainbows.rb
+++ b/lib/rainbows.rb
@@ -11,8 +11,7 @@ module Rainbows
 
   # map of numeric file descriptors to IO objects to avoid using IO.new
   # and potentially causing race conditions when using /dev/fd/
-  FD_MAP = {}
-  FD_MAP.compare_by_identity if FD_MAP.respond_to?(:compare_by_identity)
+  FD_MAP = {}.compare_by_identity
 
   require 'rainbows/const'
   require 'rainbows/http_parser'
@@ -92,7 +91,7 @@ module Rainbows
       tmp = @readers.dup
       @readers.clear
       tmp.each { |s| s.close rescue nil }.clear
-      @at_quit.each { |task| task.call }
+      @at_quit.each(&:call)
 
       # XXX hack to break out of IO.select in worker_loop for some models
       Process.kill(:QUIT, $$)
diff --git a/lib/rainbows/configurator.rb b/lib/rainbows/configurator.rb
index 92dacd6..73820a1 100644
--- a/lib/rainbows/configurator.rb
+++ b/lib/rainbows/configurator.rb
@@ -21,14 +21,14 @@
 #   stdout_path "/path/to/output.log"
 module Rainbows::Configurator
   Unicorn::Configurator::DEFAULTS.merge!({
-    :use => Rainbows::Base,
-    :worker_connections => 50,
-    :keepalive_timeout => 5,
-    :keepalive_requests => 100,
-    :client_max_body_size => 1024 * 1024,
-    :client_header_buffer_size => 1024,
-    :client_max_header_size => 112 * 1024,
-    :copy_stream => IO.respond_to?(:copy_stream) ? IO : false,
+    use: Rainbows::Base,
+    worker_connections: 50,
+    keepalive_timeout: 5,
+    keepalive_requests: 100,
+    client_max_body_size: 1024 * 1024,
+    client_header_buffer_size: 1024,
+    client_max_header_size: 112 * 1024,
+    copy_stream: IO,
   })
 
   # Configures \Rainbows! with a given concurrency model to +use+ and
diff --git a/lib/rainbows/coolio.rb b/lib/rainbows/coolio.rb
index a993060..2aba3ea 100644
--- a/lib/rainbows/coolio.rb
+++ b/lib/rainbows/coolio.rb
@@ -27,15 +27,10 @@ require 'rainbows/coolio_support'
 module Rainbows::Coolio
   # :stopdoc:
   # keep-alive timeout scoreboard
-  KATO = {}
+  KATO = {}.compare_by_identity
 
   # all connected clients
-  CONN = {}
-
-  if {}.respond_to?(:compare_by_identity)
-    CONN.compare_by_identity
-    KATO.compare_by_identity
-  end
+  CONN = {}.compare_by_identity
 
   autoload :Client, 'rainbows/coolio/client'
   autoload :Master, 'rainbows/coolio/master'
diff --git a/lib/rainbows/coolio/heartbeat.rb b/lib/rainbows/coolio/heartbeat.rb
index fcfbb0f..adea248 100644
--- a/lib/rainbows/coolio/heartbeat.rb
+++ b/lib/rainbows/coolio/heartbeat.rb
@@ -9,7 +9,7 @@ class Rainbows::Coolio::Heartbeat < Coolio::TimerWatcher
   KATO = Rainbows::Coolio::KATO
   CONN = Rainbows::Coolio::CONN
   Rainbows.config!(self, :keepalive_timeout)
-  Rainbows.at_quit { KATO.each_key { |client| client.timeout? }.clear }
+  Rainbows.at_quit { KATO.each_key(&:timeout?).clear }
 
   def on_timer
     if (ot = KEEPALIVE_TIMEOUT) >= 0
diff --git a/lib/rainbows/epoll/client.rb b/lib/rainbows/epoll/client.rb
index fe04258..85e504c 100644
--- a/lib/rainbows/epoll/client.rb
+++ b/lib/rainbows/epoll/client.rb
@@ -9,9 +9,8 @@ module Rainbows::Epoll::Client
   IN = SleepyPenguin::Epoll::IN | SleepyPenguin::Epoll::ONESHOT
   OUT = SleepyPenguin::Epoll::OUT | SleepyPenguin::Epoll::ONESHOT
   EPINOUT = IN | OUT
-  KATO = {}
-  KATO.compare_by_identity if KATO.respond_to?(:compare_by_identity)
-  Rainbows.at_quit { KATO.each_key { |k| k.timeout! }.clear }
+  KATO = {}.compare_by_identity
+  Rainbows.at_quit { KATO.each_key(&:timeout!).clear }
   Rainbows.config!(self, :keepalive_timeout)
   EP = Rainbows::EP
   @@last_expire = Rainbows.now
diff --git a/lib/rainbows/fiber/base.rb b/lib/rainbows/fiber/base.rb
index 7c4fb59..a3c098a 100644
--- a/lib/rainbows/fiber/base.rb
+++ b/lib/rainbows/fiber/base.rb
@@ -50,7 +50,7 @@ module Rainbows::Fiber::Base
         false
       end
     }
-    fibs.each { |fib| fib.resume }
+    fibs.each(&:resume)
 
     max_sleep = 1.0 # wake up semi-frequently to prevent SIGKILL from master
     if max
diff --git a/lib/rainbows/writer_thread_pool.rb b/lib/rainbows/writer_thread_pool.rb
index b5688e0..657d076 100644
--- a/lib/rainbows/writer_thread_pool.rb
+++ b/lib/rainbows/writer_thread_pool.rb
@@ -50,9 +50,9 @@ module Rainbows::WriterThreadPool
       end
     end
 
-    @@q = qp.map { |q| q.queue }
+    @@q = qp.map(&:queue)
     super(worker) # accept loop from Unicorn
-    qp.each { |q| q.quit! }
+    qp.each(&:quit!)
   end
   # :startdoc:
 end
diff --git a/lib/rainbows/xepoll_thread_pool/client.rb b/lib/rainbows/xepoll_thread_pool/client.rb
index 760bbde..ca62727 100644
--- a/lib/rainbows/xepoll_thread_pool/client.rb
+++ b/lib/rainbows/xepoll_thread_pool/client.rb
@@ -38,8 +38,7 @@ module Rainbows::XEpollThreadPool::Client
   ep = SleepyPenguin::Epoll
   EP = ep.new
   IN = ep::IN | ep::ONESHOT
-  KATO = {}
-  KATO.compare_by_identity if KATO.respond_to?(:compare_by_identity)
+  KATO = {}.compare_by_identity
   LOCK = Mutex.new
   Rainbows.at_quit do
     clients = nil
diff --git a/lib/rainbows/xepoll_thread_spawn/client.rb b/lib/rainbows/xepoll_thread_spawn/client.rb
index 67c5976..218db3e 100644
--- a/lib/rainbows/xepoll_thread_spawn/client.rb
+++ b/lib/rainbows/xepoll_thread_spawn/client.rb
@@ -27,8 +27,7 @@ module Rainbows::XEpollThreadSpawn::Client
   ep = SleepyPenguin::Epoll
   EP = ep.new
   IN = ep::IN | ep::ONESHOT
-  KATO = {}
-  KATO.compare_by_identity if KATO.respond_to?(:compare_by_identity)
+  KATO = {}.compare_by_identity
   LOCK = Mutex.new
   Rainbows.at_quit do
     clients = nil