Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimize string transformation using
String#tr
This change was flagged by RuboCop and has been verified for correctness and performance improvement. While Ruby 2.1 is no longer tested in CI, `String#tr` is supported since that version, ensuring backwards compatibility. - Replace `gsub(/_/, '-')` with `tr('_', '-')` for better performance - Improve `bench benchmark/data_attribute.haml` execution time by 20% - Maintain compatibility with Ruby 2.1 (Haml's minimum required version) Before: ``` ### IPS haml v6.3.0 94.400k i/s (0.011ms) - 473.668k ### Memory haml v6.3.0 3.264k memsize ( 600.000 retained) 41.000 objects ( 9.000 retained) 19.000 strings ( 6.000 retained) ``` After: ``` ### IPS haml v6.3.0 113.201k i/s (0.009ms) - 568.672k ### Memory haml v6.3.0 2.808k memsize ( 360.000 retained) 37.000 objects ( 6.000 retained) 19.000 strings ( 5.000 retained) ``` Refs: - https://docs.ruby-lang.org/en/2.1.0/String.html#method-i-tr - https://docs.rubocop.org/rubocop-performance/cops_performance.html#performancestringreplacement
- Loading branch information