kcar RubyGem user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
* [PATCH] kcar/response: remove const optimizations for Ruby < 2.1
@ 2015-08-04 22:21 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2015-08-04 22:21 UTC (permalink / raw)
  To: kcar-public

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).
---
 lib/kcar/response.rb | 8 +++-----
 1 file 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
-- 
EW


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2015-08-04 22:21 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-04 22:21 [PATCH] kcar/response: remove const optimizations for Ruby < 2.1 Eric Wong

Code repositories for project(s) associated with this public inbox

	https://yhbt.net/kcar.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).