Issue #17030 has been updated by fatkodima (Dima Fatko).


sawa (Tsuyoshi Sawada) wrote in #note-10:
> I feel scivola20 (sciv ola)'s idea promising, but have a concern that it is going to introduce the same kind of mess as when `"string"f` notation was introduced (same "f" used due to frozen and fast, but this is just coincidental). People are going to need to write `/regex/f` all over the place.
> 
> Just by analogy from the situation with strings, what about introducing the following pragma, which will make all regex literals on that page fast regex literals (i.e., `===` becomes `match?`)?
> 
> ```ruby
> # boolean_regex_literal: true
> ```
> 
> And perhaps in the long run, Matz might want to make all regexes work like that, or simply change the definition of `Regexp#===`.


Yes, seems like this will solve the problem of typing `regex/f` all over. Does it also mean that we then should have something like in frozen string world (`String#@+`) to manually change to the old behavior where we need it, like

```ruby
# boolean_regex_literal: true

case var
when /foo/
  # does not set $~, etc
when +/bar/
  # sets $~, etc
end
```
?

----------------------------------------
Bug #17030: Enumerable#grep{_v} should be optimized for Regexp
https://bugs.ruby-lang.org/issues/17030#change-87192

* Author: marcandre (Marc-Andre Lafortune)
* Status: Open
* Priority: Normal
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
----------------------------------------
Currently:

```ruby
array.select { |e| e.match?(REGEXP) }

# about 3x faster and 6x more memory efficient than
array.grep(REGEXP)
```

This is because `grep` calls `Regexp#===` which creates useless `MatchData`



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>