Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Performance/StringIdentifierArgument aware of string interpolation #387

Merged
merged 1 commit into from
Nov 21, 2023
Merged

Make Performance/StringIdentifierArgument aware of string interpolation #387

merged 1 commit into from
Nov 21, 2023

Conversation

Earlopain
Copy link
Contributor

Closes #386, see there for benchmark script. The improvement isn't quite as large as for the other cases of this cop but it's still measurable. In addition it makes the code more uniform.


Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.

…ment`

Makes the cop aware of string interpolation.

```rb
require 'benchmark/ips'

puts `ruby -v`

def foo_bar
end

bar = "bar"

Benchmark.ips do |x|
  x.report('symbol arg') { send(:"foo_#{bar}") }
  x.report('string arg') { send("foo_#{bar}") }

  x.compare!
end
```

```
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x86_64-linux-musl]
Warming up --------------------------------------
          symbol arg   641.253k i/100ms
          string arg   602.373k i/100ms
Calculating -------------------------------------
          symbol arg      6.385M (± 0.6%) i/s -     32.063M in   5.022123s
          string arg      6.023M (± 0.5%) i/s -     30.119M in   5.000717s

Comparison:
          symbol arg:  6384545.4 i/s
          string arg:  6023007.5 i/s - 1.06x  slower
```
@koic koic merged commit 8232082 into rubocop:master Nov 21, 2023
10 checks passed
@koic
Copy link
Member

koic commented Nov 21, 2023

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

False negative for Performance/StringIdentifierArgument with string interpolation
2 participants