Patch #34161
Replace gsub with tr, delete, or squeeze
Status: | Closed | Start date: | ||
---|---|---|---|---|
Priority: | Normal | Due date: | ||
Assignee: | % Done: | 0% | ||
Category: | Performance | |||
Target version: | 4.2.0 |
Description
String#tr
, String#delete
, and String#squeeze
are faster than String#gsub
.
https://docs.rubocop.org/rubocop-performance/cops_performance.html#performancestringreplacement
https://github.com/JuanitoFatas/fast-ruby#stringgsub-vs-stringtr-code
https://docs.rubocop.org/rubocop-performance/cops_performance.html#performancesqueeze
https://github.com/JuanitoFatas/fast-ruby#remove-extra-spaces-or-other-contiguous-characters-code
Replacement can be done with RuboCop:
bundle exec rubocop --only Performance/StringReplacement,Performance/Squeeze -a
Associated revisions
Replace gsub with tr, delete, or squeeze (#34161).