about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2014-11-20 03:53:47 +0000
committerEric Wong <e@80x24.org>2014-11-20 20:35:27 +0000
commitd992c14cf0b45aaba89ff5bab86122caf07c48ab (patch)
treec0745e68b3cef99056d7b52b8dc6bbec6e0cd477
parent3c5e36cd57fa32c85afe26d47a5a7d2314a7360a (diff)
downloadyahns-d992c14cf0b45aaba89ff5bab86122caf07c48ab.tar.gz
Ruby 2.1 optimizes String#freeze by deduplicating string literal
calls to freeze.  Ruby 2.2 _may_ also optimize away allocations to
Hash#delete in the future.  In any case, this is uncommon code and
not worth trading permanent space to reduce temporal garbage.

While this favors Ruby 2.1 and later, it remains completely
compatible with Ruby 1.9.3 and 2.0.0.
-rw-r--r--lib/yahns/http_response.rb9
1 files changed, 4 insertions, 5 deletions
diff --git a/lib/yahns/http_response.rb b/lib/yahns/http_response.rb
index e48e57c..0b0296f 100644
--- a/lib/yahns/http_response.rb
+++ b/lib/yahns/http_response.rb
@@ -28,9 +28,6 @@ module Yahns::HttpResponse # :nodoc:
   Z = ""
   CCC_RESPONSE_START = [ 'HTTP', '/1.1 ' ]
   RESPONSE_START = CCC_RESPONSE_START.join
-  R100_RAW = "HTTP/1.1 100 Continue\r\n\r\n"
-  R100_CCC = "100 Continue\r\n\r\nHTTP/1.1 "
-  HTTP_EXPECT = "HTTP_EXPECT"
   REQUEST_METHOD = "REQUEST_METHOD"
   HEAD = "HEAD"
 
@@ -258,8 +255,10 @@ module Yahns::HttpResponse # :nodoc:
   # returns nil on success
   # returns :close, :wait_writable, or :wait_readable
   def http_100_response(env)
-    env.delete(HTTP_EXPECT) =~ /\A100-continue\z/i or return nil
-    buf = @response_start_sent ? R100_CCC : R100_RAW
+    env.delete("HTTP_EXPECT") =~ /\A100-continue\z/i or return
+    buf = @response_start_sent ? "100 Continue\r\n\r\nHTTP/1.1 ".freeze
+                               : "HTTP/1.1 100 Continue\r\n\r\n".freeze
+
     case rv = kgio_trywrite(buf)
     when String
       buf = rv