From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id B20142021E for ; Sat, 29 Oct 2016 01:31:43 +0000 (UTC) From: Eric Wong 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 Message-Id: <20161029013143.4186-1-e@80x24.org> List-Id: 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