about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2015-07-21 21:03:48 +0000
committerEric Wong <e@80x24.org>2015-07-21 21:03:48 +0000
commit522ded71a61549d8222105f99e408fd4622aba14 (patch)
tree3148408e7db998b889ed9a5b68af084b24dc93c2
parentd6f0635e0afd50c44a9fa7f7df4033232588057a (diff)
downloadkcar-522ded71a61549d8222105f99e408fd4622aba14.tar.gz
kcar/response: remove const optimizations for Ruby < 2.1
Ruby 2.1 and later emits opt_str_freeze to deduplicate literal
String#freeze calls, leading to even better performance than
the overhead from constant lookups (which have inline cache
overhead).
-rw-r--r--lib/kcar/response.rb8
1 files changed, 3 insertions, 5 deletions
diff --git a/lib/kcar/response.rb b/lib/kcar/response.rb
index dba7fc8..954502c 100644
--- a/lib/kcar/response.rb
+++ b/lib/kcar/response.rb
@@ -7,8 +7,6 @@ class Kcar::Response
   attr_accessor :sock, :hdr, :unchunk, :buf, :parser
 
   # :stopdoc:
-  LAST_CHUNK = "0\r\n"
-  CRLF = "\r\n"
   Parser = Kcar::Parser
   # :startdoc:
 
@@ -91,12 +89,12 @@ class Kcar::Response
       size = dst.size
       if size > 0
         yield("#{size.to_s(16)}\r\n")
-        yield(dst << CRLF)
+        yield(dst << "\r\n".freeze)
       end
       break if @parser.body_eof?
     end while @buf << @sock.readpartial(READ_SIZE, dst)
 
-    yield LAST_CHUNK
+    yield "0\r\n".freeze
 
     until @parser.trailers(@hdr, @buf)
       @buf << @sock.readpartial(READ_SIZE, dst)
@@ -106,7 +104,7 @@ class Kcar::Response
     # in the response, we'll just yield a stringified version to our
     # server and pretend it's part of the body.
     trailers = @parser.extract_trailers(@hdr)
-    yield(trailers.map! { |k,v| "#{k}: #{v}\r\n" }.join << CRLF)
+    yield(trailers.map! { |k,v| "#{k}: #{v}\r\n" }.join << "\r\n".freeze)
   end
 
   def each_until_eof