From: Eric Wong <e@80x24.org>
To: kcar-public@bogomips.org
Subject: [PATCH] kcar/response: remove const optimizations for Ruby < 2.1
Date: Tue, 4 Aug 2015 22:21:41 +0000 [thread overview]
Message-ID: <1438726901-15284-1-git-send-email-e@80x24.org> (raw)
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
reply other threads:[~2015-08-04 22:21 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://yhbt.net/kcar/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1438726901-15284-1-git-send-email-e@80x24.org \
--to=e@80x24.org \
--cc=kcar-public@bogomips.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).