Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@tagliala
Copy link
Contributor

Support for Ruby versions earlier than 3.2 has been dropped, ensuring that Regexp#match?, introduced in Ruby 2.4, is available on all supported Rubies.

This commit uses match? for more efficient regular expression checks.

Automatically corrected via

rubocop --plugin rubocop-performance --only Performance/RegexpMatch -a

Follow up of #1176


Benchmarks

Slightly modified bin/bench with benchmark-memory.

data attributes

Before

$ ./bin/bench compile benchmark/data_attribute.haml 
=================================================
 Compilation: benchmark/data_attribute.haml
=================================================
Calculating -------------------------------------
         haml v7.0.0   148.000  i/100ms
-------------------------------------------------
         haml v7.0.0      1.500k i/s (0.667ms) -     15.096k
Calculating -------------------------------------
         haml v7.0.0   171.077k memsize (     0.000  retained)
                         2.155k objects (     0.000  retained)
                        50.000  strings (     0.000  retained)

After

$ ./bin/bench compile benchmark/data_attribute.haml 
=================================================
 Compilation: benchmark/data_attribute.haml
=================================================
Calculating -------------------------------------
     haml v7.0.0-dev   150.000  i/100ms
-------------------------------------------------
     haml v7.0.0-dev      1.532k i/s (0.653ms) -     15.450k
Calculating -------------------------------------
     haml v7.0.0-dev   170.293k memsize (     0.000  retained)
                         2.149k objects (     0.000  retained)
                        50.000  strings (     0.000  retained)

filter

Template

:javascript
  // Hello
:preserve
  Hello

Before

$ bin/bench compile benchmark/filter.haml 
=================================================
 Compilation: benchmark/filter.haml
=================================================
Calculating -------------------------------------
         haml v7.0.0   273.000  i/100ms
-------------------------------------------------
         haml v7.0.0      2.729k i/s (0.366ms) -     27.300k
Calculating -------------------------------------
         haml v7.0.0    69.871k memsize (     0.000  retained)
                       723.000  objects (     0.000  retained)
                        50.000  strings (     0.000  retained)

After

$ ./bin/bench compile benchmark/filter.haml 
=================================================
 Compilation: benchmark/filter.haml
=================================================
Calculating -------------------------------------
     haml v7.0.0-dev   281.000  i/100ms
-------------------------------------------------
     haml v7.0.0-dev      2.731k i/s (0.366ms) -     27.257k
Calculating -------------------------------------
     haml v7.0.0-dev    69.375k memsize (     0.000  retained)
                       719.000  objects (     0.000  retained)
                        50.000  strings (     0.000  retained)

Support for Ruby versions earlier than 3.2 has been dropped, ensuring
that `Regexp#match?`, introduced in Ruby 2.4, is available on all
supported Rubies.

This commit uses `match?` for more efficient regular expression checks.

Automatically corrected via

```
rubocop --plugin rubocop-performance --only Performance/RegexpMatch -a
```

Follow up of haml#1176
@k0kubun k0kubun merged commit ca3a039 into haml:main Oct 30, 2025
6 checks passed
@tagliala tagliala deleted the performance/match-predicate branch October 30, 2025 07:43
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.

2 participants