From: eregontp@... Date: 2020-08-28T15:30:28+00:00 Subject: [ruby-core:99752] [Ruby master Bug#17030] Enumerable#grep{_v} should be optimized for Regexp Issue #17030 has been updated by Eregon (Benoit Daloze). I'm surprised at the performance difference on MRI though. Just allocating the MatchData shouldn't be so expensive. Maybe `Regexp#match?` has additional optimizations? ---------------------------------------- Bug #17030: Enumerable#grep{_v} should be optimized for Regexp https://bugs.ruby-lang.org/issues/17030#change-87252 * 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) } ``` is about three times faster and six times more memory efficient than ```ruby array.grep(REGEXP) ``` This is because `grep` calls `Regexp#===`, which creates useless `MatchData`. -- https://bugs.ruby-lang.org/ Unsubscribe: