[ruby-core:99687] [Ruby master Bug#17030] Enumerable#grep{_v} should be optimized for Regexp
From:
fatkodima123@...
Date:
2020-08-25 17:23:44 UTC
List:
ruby-core #99687
Issue #17030 has been updated by fatkodima (Dima Fatko).
I like @scivola20 's idea and would like to try to implement it.
Before starting, @nobu, wdyt, is this something that will be merged?
----------------------------------------
Bug #17030: Enumerable#grep{_v} should be optimized for Regexp
https://bugs.ruby-lang.org/issues/17030#change-87177
* 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:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>