From 677208d32de42da65befd49b1815cfe6ae6a3231 Mon Sep 17 00:00:00 2001 From: normal Date: Sun, 10 Jan 2016 00:35:43 +0000 Subject: stdlib: avoid extra calls to eliminate "\n" from Base64 We may use the '0' (zero) to avoid adding the line feed. Furthermore, the '*' (asterisk) modifier is not needed for a single-element arrays. * ext/psych/lib/psych/visitors/yaml_tree.rb (visit_String): eliminate chomp * lib/net/http.rb (connect): eliminate delete * lib/net/http/header.rb (basic_encode): ditto * lib/net/imap.rb (authenticate): eliminate gsub (self.encode_utf7): shorten delete arg * lib/net/smtp.rb (base64_encode): eliminate gsub * lib/open-uri.rb (OpenURI.open_http): eliminate delete * lib/rss/rss.rb: ditto * lib/securerandom.rb (base64): ditto (urlsafe_base64): eliminate delete! * lib/webrick/httpauth/digestauth.rb (split_param_value): eliminate chop * lib/webrick/httpproxy.rb (do_CONNECT): eliminate delete (setup_upstream_proxy_authentication): ditto [ruby-core:72666] [Feature #11938] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53488 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/webrick/httpauth/digestauth.rb | 2 +- lib/webrick/httpproxy.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/webrick') diff --git a/lib/webrick/httpauth/digestauth.rb b/lib/webrick/httpauth/digestauth.rb index 018989e6dd..98bdbd10c7 100644 --- a/lib/webrick/httpauth/digestauth.rb +++ b/lib/webrick/httpauth/digestauth.rb @@ -312,7 +312,7 @@ module WEBrick def generate_next_nonce(req) now = "%012d" % req.request_time.to_i pk = hexdigest(now, @instance_key)[0,32] - nonce = [now + ":" + pk].pack("m*").chop # it has 60 length of chars. + nonce = [now + ":" + pk].pack("m0") # it has 60 length of chars. nonce end diff --git a/lib/webrick/httpproxy.rb b/lib/webrick/httpproxy.rb index 79a2e8f55b..083720f298 100644 --- a/lib/webrick/httpproxy.rb +++ b/lib/webrick/httpproxy.rb @@ -143,7 +143,7 @@ module WEBrick if proxy = proxy_uri(req, res) proxy_request_line = "CONNECT #{host}:#{port} HTTP/1.0" if proxy.userinfo - credentials = "Basic " + [proxy.userinfo].pack("m").delete("\n") + credentials = "Basic " + [proxy.userinfo].pack("m0") end host, port = proxy.host, proxy.port end @@ -294,7 +294,7 @@ module WEBrick if upstream = proxy_uri(req, res) if upstream.userinfo header['proxy-authorization'] = - "Basic " + [upstream.userinfo].pack("m").delete("\n") + "Basic " + [upstream.userinfo].pack("m0") end return upstream end -- cgit v1.2.3