From: Eric Wong <e@80x24.org>
To: http_spew-public@bogomips.org
Subject: [PATCH] rely on opt_str_freeze in more places
Date: Sat, 29 Oct 2016 01:31:43 +0000 [thread overview]
Message-ID: <20161029013143.4186-1-e@80x24.org> (raw)
These strings are obviously never modified, avoid
allocations, even if they are corner cases.
---
GNUmakefile | 2 +-
lib/http_spew/class_methods.rb | 4 ++--
lib/http_spew/content_md5.rb | 7 ++++---
| 2 +-
4 files changed, 8 insertions(+), 7 deletions(-)
diff --git a/GNUmakefile b/GNUmakefile
index 0604222..3c36761 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -9,7 +9,7 @@ include pkg.mk
$(RUBY_VERSION_FILE): GIT-VERSION-FILE
@$(RM) -f $@+
@echo >> $@+ '# -*- encoding: binary -*-'
- @echo >> $@+ 'HTTP_Spew.const_set :VERSION, "$(GIT_VERSION)"'
+ @echo >> $@+ 'HTTP_Spew.const_set :VERSION, "$(GIT_VERSION)".freeze'
@mv $@+ $@
build: $(RUBY_VERSION_FILE)
diff --git a/lib/http_spew/class_methods.rb b/lib/http_spew/class_methods.rb
index 1569de4..938b55c 100644
--- a/lib/http_spew/class_methods.rb
+++ b/lib/http_spew/class_methods.rb
@@ -60,7 +60,7 @@ module HTTP_Spew::ClassMethods
active << Thread.new do
begin
rv = req.run(timeout)
- w.write([ i ].pack("v"))
+ w.write([ i ].pack("v".freeze))
rv
rescue => err
err
@@ -69,7 +69,7 @@ module HTTP_Spew::ClassMethods
end
begin
with_timeout(t) { r.kgio_wait_readable(t[0]) }
- req_idx = r.read(2).unpack("v")[0]
+ req_idx = r.read(2).unpack("v".freeze)[0]
thr = active[req_idx]
with_timeout(t) { thr.join(t[0]) }
rv = thr.value
diff --git a/lib/http_spew/content_md5.rb b/lib/http_spew/content_md5.rb
index a999111..ed68523 100644
--- a/lib/http_spew/content_md5.rb
+++ b/lib/http_spew/content_md5.rb
@@ -10,12 +10,13 @@ class HTTP_Spew::ContentMD5
def initialize(env, input = env["rack.input"])
if trailer = env["HTTP_TRAILER"]
unless trailer.split(/\s*,\s*/).grep(/\AContent-MD5\z/i)[0]
- trailer << (trailer.empty? ? "Content-MD5" : ",Content-MD5")
+ trailer << (trailer.empty? ? "Content-MD5".freeze
+ : ",Content-MD5".freeze)
end
else
- env["HTTP_TRAILER"] = "Content-MD5"
+ env["HTTP_TRAILER"] = "Content-MD5".freeze
end
- env["HTTP_TRANSFER_ENCODING"] = "chunked"
+ env["HTTP_TRANSFER_ENCODING"] = "chunked".freeze
@to_io, wr = HTTP_Spew::ChunkyPipe.new
expect_md5 = env.delete("HTTP_CONTENT_MD5")
expect_len = env.delete("CONTENT_LENGTH")
--git a/lib/http_spew/headers.rb b/lib/http_spew/headers.rb
index 6f6f4d0..f121fd2 100644
--- a/lib/http_spew/headers.rb
+++ b/lib/http_spew/headers.rb
@@ -34,7 +34,7 @@ module HTTP_Spew::Headers
if input
req << (input.respond_to?(:size) ?
"Content-Length: #{input.size}\r\n" :
- "Transfer-Encoding: chunked\r\n")
+ "Transfer-Encoding: chunked\r\n".freeze)
ct = env['CONTENT_TYPE'] and req << "Content-Type: #{ct}\r\n"
end
req << "\r\n".freeze
--
EW
reply other threads:[~2016-10-29 1:31 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/http_spew/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20161029013143.4186-1-e@80x24.org \
--to=e@80x24.org \
--cc=http_spew-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/http_spew.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox