From: marcandre-ruby-core@... Date: 2020-08-26T15:01:02+00:00 Subject: [ruby-core:99705] [Ruby master Bug#17030] Enumerable#grep{_v} should be optimized for Regexp Issue #17030 has been updated by marcandre (Marc-Andre Lafortune). Couldn't static analysis of the code determine in most cases if match data need be generated or not? This is Ruby, so I can think of some corner cases where things like `const_get(:Regexp).last_match` would be impacted (in theory), what other limitations would this have? Maybe it would be best to start a different thread as none of these proposals have a relation to `grep{_v}` without block not being optimized. ---------------------------------------- Bug #17030: Enumerable#grep{_v} should be optimized for Regexp https://bugs.ruby-lang.org/issues/17030#change-87196 * 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: