From: marcandre-ruby-core@... Date: 2020-08-26T19:31:50+00:00 Subject: [ruby-core:99714] [Ruby master Bug#17030] Enumerable#grep{_v} should be optimized for Regexp Issue #17030 has been updated by marcandre (Marc-Andre Lafortune). Dan0042 (Daniel DeLorme) wrote in #note-15: > But static analysis has other limits Good example but it is easily resolved: assume `v` isn't a Regexp and we may get a false positive, which is not a big issue. There will be other false positives: `str.gsub(regexp, &block)`. That's not a real issue, simply assume that `block` will want access to `Regexp.last_match`. I'm really only worried about false negatives... Any other example comes to mind? ---------------------------------------- Bug #17030: Enumerable#grep{_v} should be optimized for Regexp https://bugs.ruby-lang.org/issues/17030#change-87204 * 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: