RuboCop: Fix all offenses for Performance/StringIdentifierArgument
What does this MR do and why?
This MR fixes all offenses for Performance/StringIdentifierArgument
.
Done via:
rubocop -A --only Performance/StringIdentifierArgument
Verified via:
rake rubocop:todo:generate[Performance/StringIdentifierArgument]
Thus, empty todo file removed.
Contributes to #239356
Micro benchmarks
TLDR; Using String is ~1.7x slower.
# frozen_string_literal: true
require "benchmark/ips"
o = Object.new
Benchmark.ips do |x|
x.report "string" do
o.instance_variable_defined?("@x")
end
x.report "symbol" do
o.instance_variable_defined?(:@x)
end
x.compare!
end
Results
Warming up --------------------------------------
string 1.400M i/100ms
symbol 2.436M i/100ms
Calculating -------------------------------------
string 13.907M (± 0.3%) i/s - 69.995M in 5.033067s
symbol 24.228M (± 2.8%) i/s - 121.784M in 5.031130s
Comparison:
symbol: 24227885.9 i/s
string: 13907236.4 i/s - 1.74x (± 0.00) slower
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Edited by Peter Leitzen