about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2011-01-21 15:08:07 -0800
committerEric Wong <normalperson@yhbt.net>2011-01-21 16:54:02 -0800
commit43d6ec33c3dd7497e27127adfffeb94722fd4b8d (patch)
tree7f4e519e67900f9d2d5fb9465fbf28d48a4cc1d0
parent247ce76b4aabfa42157b9cbf9ebae824819cfff6 (diff)
downloadrainbows-43d6ec33c3dd7497e27127adfffeb94722fd4b8d.tar.gz
We don't need to allocate new string objects for short-lived
strings.  We'll pay the price of a constant lookup instead.
-rw-r--r--lib/rainbows/coolio/client.rb2
-rw-r--r--lib/rainbows/epoll/client.rb6
-rw-r--r--lib/rainbows/ev_core.rb5
-rw-r--r--lib/rainbows/event_machine/client.rb2
4 files changed, 8 insertions, 7 deletions
diff --git a/lib/rainbows/coolio/client.rb b/lib/rainbows/coolio/client.rb
index 6561207..0ccccff 100644
--- a/lib/rainbows/coolio/client.rb
+++ b/lib/rainbows/coolio/client.rb
@@ -142,7 +142,7 @@ class Rainbows::Coolio::Client < Coolio::IO
           KATO[self] = Time.now
         end
       else
-        on_read("")
+        on_read(Z)
       end
     end
     rescue => e
diff --git a/lib/rainbows/epoll/client.rb b/lib/rainbows/epoll/client.rb
index cb7097d..ba9d576 100644
--- a/lib/rainbows/epoll/client.rb
+++ b/lib/rainbows/epoll/client.rb
@@ -75,7 +75,7 @@ module Rainbows::Epoll::Client
                     Rainbows::Epoll::ResponsePipe).new(io, self, body)
     return @wr_queue << pipe if @wr_queue[0]
     stream_pipe(pipe) or return
-    @wr_queue[0] or @wr_queue << ""
+    @wr_queue[0] or @wr_queue << Z
   end
 
   def ev_write_response(status, headers, body, alive)
@@ -85,7 +85,7 @@ module Rainbows::Epoll::Client
       write_response(status, headers, body, alive)
     end
     @state = alive ? :headers : :close
-    on_read("") if alive && 0 == @wr_queue.size && 0 != @buf.size
+    on_read(Z) if alive && 0 == @wr_queue.size && 0 != @buf.size
   end
 
   def epoll_run
@@ -103,7 +103,7 @@ module Rainbows::Epoll::Client
 
   def on_deferred_write_complete
     :close == @state and return close
-    0 == @buf.size ? on_readable : on_read("")
+    0 == @buf.size ? on_readable : on_read(Z)
   end
 
   def handle_error(e)
diff --git a/lib/rainbows/ev_core.rb b/lib/rainbows/ev_core.rb
index 8d3511a..826dce6 100644
--- a/lib/rainbows/ev_core.rb
+++ b/lib/rainbows/ev_core.rb
@@ -8,6 +8,7 @@ module Rainbows::EvCore
   HttpParser = Rainbows::HttpParser
   autoload :CapInput, 'rainbows/ev_core/cap_input'
   RBUF = ""
+  Z = "".freeze
 
   # Apps may return this Rack response: AsyncResponse = [ -1, {}, [] ]
   ASYNC_CALLBACK = "async.callback".freeze
@@ -71,7 +72,7 @@ module Rainbows::EvCore
     @input = mkinput
     @hp.filter_body(@buf2 = "", @buf)
     @input << @buf2
-    on_read("")
+    on_read(Z)
   end
 
   # TeeInput doesn't map too well to this right now...
@@ -99,7 +100,7 @@ module Rainbows::EvCore
       elsif data.size > 0
         @hp.filter_body(@buf2, @buf << data)
         @input << @buf2
-        on_read("")
+        on_read(Z)
       else
         want_more
       end
diff --git a/lib/rainbows/event_machine/client.rb b/lib/rainbows/event_machine/client.rb
index b75d7ee..1b15daa 100644
--- a/lib/rainbows/event_machine/client.rb
+++ b/lib/rainbows/event_machine/client.rb
@@ -21,7 +21,7 @@ class Rainbows::EventMachine::Client < EM::Connection
       end
       EM.next_tick { receive_data(nil) } unless @buf.empty?
     else
-      on_read(data || "") if (@buf.size > 0) || data
+      on_read(data || Z) if (@buf.size > 0) || data
     end
   end