Skip to content

Commit 82d1848

Browse files
authored
Merge pull request rails#32971 from y-yagi/use_plus_operator_to_unfreeze_string
Enable `Performance/UnfreezeString` cop
2 parents d3b9521 + 1b86d90 commit 82d1848

File tree

101 files changed

+366
-364
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+366
-364
lines changed

.rubocop.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,3 +208,6 @@ Performance/EndWith:
208208

209209
Performance/RegexpMatch:
210210
Enabled: true
211+
212+
Performance/UnfreezeString:
213+
Enabled: true

actioncable/lib/action_cable/channel/base.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ def dispatch_action(action, data)
270270
end
271271

272272
def action_signature(action, data)
273-
"#{self.class.name}##{action}".dup.tap do |signature|
273+
(+"#{self.class.name}##{action}").tap do |signature|
274274
if (arguments = data.except("action")).any?
275275
signature << "(#{arguments.inspect})"
276276
end

actionmailer/test/base_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class BaseTest < ActiveSupport::TestCase
122122
email = BaseMailer.attachment_with_hash
123123
assert_equal(1, email.attachments.length)
124124
assert_equal("invoice.jpg", email.attachments[0].filename)
125-
expected = "\312\213\254\232)b".dup
125+
expected = +"\312\213\254\232)b"
126126
expected.force_encoding(Encoding::BINARY)
127127
assert_equal expected, email.attachments["invoice.jpg"].decoded
128128
end
@@ -131,7 +131,7 @@ class BaseTest < ActiveSupport::TestCase
131131
email = BaseMailer.attachment_with_hash_default_encoding
132132
assert_equal(1, email.attachments.length)
133133
assert_equal("invoice.jpg", email.attachments[0].filename)
134-
expected = "\312\213\254\232)b".dup
134+
expected = +"\312\213\254\232)b"
135135
expected.force_encoding(Encoding::BINARY)
136136
assert_equal expected, email.attachments["invoice.jpg"].decoded
137137
end

actionpack/lib/action_controller/log_subscriber.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def process_action(event)
2626
exception_class_name = payload[:exception].first
2727
status = ActionDispatch::ExceptionWrapper.status_code_for_exception(exception_class_name)
2828
end
29-
message = "Completed #{status} #{Rack::Utils::HTTP_STATUS_CODES[status]} in #{event.duration.round}ms".dup
29+
message = +"Completed #{status} #{Rack::Utils::HTTP_STATUS_CODES[status]} in #{event.duration.round}ms"
3030
message << " (#{additions.join(" | ".freeze)})" unless additions.empty?
3131
message << "\n\n" if defined?(Rails.env) && Rails.env.development?
3232

actionpack/lib/action_controller/metal/http_authentication.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ def params_array_from(raw_params)
474474

475475
# This removes the <tt>"</tt> characters wrapping the value.
476476
def rewrite_param_values(array_params)
477-
array_params.each { |param| (param[1] || "".dup).gsub! %r/^"|"$/, "" }
477+
array_params.each { |param| (param[1] || +"").gsub! %r/^"|"$/, "" }
478478
end
479479

480480
# This method takes an authorization body and splits up the key-value

actionpack/lib/action_controller/metal/live.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ def log_error(exception)
297297
return unless logger
298298

299299
logger.fatal do
300-
message = "\n#{exception.class} (#{exception.message}):\n".dup
300+
message = +"\n#{exception.class} (#{exception.message}):\n"
301301
message << exception.annoted_source_code.to_s if exception.respond_to?(:annoted_source_code)
302302
message << " " << exception.backtrace.join("\n ")
303303
"#{message}\n\n"

actionpack/lib/action_controller/metal/rendering.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def render(*args) #:nodoc:
4040
def render_to_string(*)
4141
result = super
4242
if result.respond_to?(:each)
43-
string = "".dup
43+
string = +""
4444
result.each { |r| string << r }
4545
string
4646
else

actionpack/lib/action_dispatch/http/response.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def initialize(response, buf)
105105

106106
def body
107107
@str_body ||= begin
108-
buf = "".dup
108+
buf = +""
109109
each { |chunk| buf << chunk }
110110
buf
111111
end

actionpack/lib/action_dispatch/http/url.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def normalize_host(_host, options)
157157
subdomain = options.fetch :subdomain, true
158158
domain = options[:domain]
159159

160-
host = "".dup
160+
host = +""
161161
if subdomain == true
162162
return _host if domain.nil?
163163

actionpack/lib/action_dispatch/journey/formatter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def generate(name, options, path_parameters, parameterize = nil)
5050
unmatched_keys = (missing_keys || []) & constraints.keys
5151
missing_keys = (missing_keys || []) - unmatched_keys
5252

53-
message = "No route matches #{Hash[constraints.sort_by { |k, v| k.to_s }].inspect}".dup
53+
message = +"No route matches #{Hash[constraints.sort_by { |k, v| k.to_s }].inspect}"
5454
message << ", missing required keys: #{missing_keys.sort.inspect}" if missing_keys && !missing_keys.empty?
5555
message << ", possible unmatched constraints: #{unmatched_keys.sort.inspect}" if unmatched_keys && !unmatched_keys.empty?
5656

0 commit comments

Comments
 (0)