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.
---
 lib/yahns/http_response.rb | 9 ++++-----
 1 file 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
-- 
EW


Reply via email to