http_spew RubyGem user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
* [PATCH] rely on opt_str_freeze in more places
@ 2016-10-29  1:31 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2016-10-29  1:31 UTC (permalink / raw)
  To: http_spew-public

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 ++++---
 lib/http_spew/headers.rb       | 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")
diff --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


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

only message in thread, other threads:[~2016-10-29  1:31 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-29  1:31 [PATCH] rely on opt_str_freeze in more places Eric Wong

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