about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2015-06-30 02:54:26 +0000
committerEric Wong <e@80x24.org>2015-06-30 02:54:26 +0000
commitd3f28e0fa44318f9af4409fc9b865d5094ccc1ee (patch)
tree142393f8c3453cba77517881b04ff3e809b9bae8 /lib
parent0d1ec2d1b864f3d39b4bf67fa6ac6c4aedc18136 (diff)
downloadyahns-d3f28e0fa44318f9af4409fc9b865d5094ccc1ee.tar.gz
This saves around 200 bytes on x86-64 and potentially improves
CPU cache performance.  This does not reduce inline method
cache overhead as String#<< already has optimized dispatch
support (opt_ltlt in insns.def in Ruby 1.9+)
Diffstat (limited to 'lib')
-rw-r--r--lib/yahns/http_response.rb12
1 files changed, 6 insertions, 6 deletions
diff --git a/lib/yahns/http_response.rb b/lib/yahns/http_response.rb
index f50c9a1..19075bb 100644
--- a/lib/yahns/http_response.rb
+++ b/lib/yahns/http_response.rb
@@ -108,12 +108,12 @@ module Yahns::HttpResponse # :nodoc:
     end
   end
 
-  def kv_str(key, value)
+  def kv_str(buf, key, value)
     if value.include?("\n".freeze)
       # avoiding blank, key-only cookies with /\n+/
-      value.split(/\n+/).map! { |v| "#{key}: #{v}\r\n" }.join
+      value.split(/\n+/).each { |v| buf << "#{key}: #{v}\r\n" }
     else
-      "#{key}: #{value}\r\n"
+      buf << "#{key}: #{value}\r\n"
     end
   end
 
@@ -144,17 +144,17 @@ module Yahns::HttpResponse # :nodoc:
             offset = $1.to_i
             count = $2.to_i - offset + 1
           end
-          buf << kv_str(key, value)
+          kv_str(buf, key, value)
         when %r{\AConnection\z}i
           # allow Rack apps to tell us they want to drop the client
           alive = false if value =~ /\bclose\b/i
         when %r{\AContent-Length\z}i
           flags |= MSG_MORE if have_more?(value)
-          buf << kv_str(key, value)
+          kv_str(buf, key, value)
         when "rack.hijack"
           hijack = value
         else
-          buf << kv_str(key, value)
+          kv_str(buf, key, value)
         end
       end
       buf << (alive ? "Connection: keep-alive\r\n\r\n".freeze