diff options
author | Akira Matsuda <ronnie@dio.jp> | 2022-05-11 05:25:32 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-11 08:25:32 +1200 |
commit | f0c79c9b1a387d426ef7a9ae9216b759b38d13b1 (patch) | |
tree | 6cc4a1022b58e07ae397f28c7943d320af8472d3 | |
parent | 1d71f8741bb8343711924505a2bbc82159667691 (diff) | |
download | rack-f0c79c9b1a387d426ef7a9ae9216b759b38d13b1.tar.gz |
Prefer Kernel#sprintf over String#% where passing in multiple values (#1889)
because String#% takes the arguments as an Array, which ends up in allocating an extra Array object
-rw-r--r-- | lib/rack/common_logger.rb | 4 | ||||
-rw-r--r-- | lib/rack/server.rb | 2 |
2 files changed, 3 insertions, 3 deletions
diff --git a/lib/rack/common_logger.rb b/lib/rack/common_logger.rb index d833e2e1..53f42cc5 100644 --- a/lib/rack/common_logger.rb +++ b/lib/rack/common_logger.rb @@ -52,7 +52,7 @@ module Rack request = Rack::Request.new(env) length = extract_content_length(response_headers) - msg = FORMAT % [ + msg = sprintf(FORMAT, request.ip || "-", request.get_header("REMOTE_USER") || "-", Time.now.strftime("%d/%b/%Y:%H:%M:%S %z"), @@ -63,7 +63,7 @@ module Rack request.get_header(SERVER_PROTOCOL), status.to_s[0..3], length, - Utils.clock_time - began_at ] + Utils.clock_time - began_at) logger = @logger || request.get_header(RACK_ERRORS) # Standard library logger doesn't support write but it supports << which actually diff --git a/lib/rack/server.rb b/lib/rack/server.rb index 7d0fe076..3b362b21 100644 --- a/lib/rack/server.rb +++ b/lib/rack/server.rb @@ -145,7 +145,7 @@ module Rack has_options = false server.valid_options.each do |name, description| next if /^(Host|Port)[^a-zA-Z]/.match?(name.to_s) # ignore handler's host and port options, we do our own. - info << " -O %-21s %s" % [name, description] + info << sprintf(" -O %-21s %s", name, description) has_options = true end return "" if !has_options |