From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by dcvr.yhbt.net (Postfix) with ESMTP id A78C81F5AE for ; Tue, 14 Jul 2020 13:46:20 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 5FBEA120A1F; Tue, 14 Jul 2020 22:45:48 +0900 (JST) Received: from xtrwkhkc.outbound-mail.sendgrid.net (xtrwkhkc.outbound-mail.sendgrid.net [167.89.16.28]) by neon.ruby-lang.org (Postfix) with ESMTPS id 09439120A1D for ; Tue, 14 Jul 2020 22:45:45 +0900 (JST) Received: by filterdrecv-p3iad2-5b55dcd864-xvj6x with SMTP id filterdrecv-p3iad2-5b55dcd864-xvj6x-20-5F0DB722-40 2020-07-14 13:46:10.147182703 +0000 UTC m=+1543014.254819741 Received: from herokuapp.com (unknown) by geopod-ismtpd-1-3 (SG) with ESMTP id CZ4G10JCQj-uezBAhgGZfA for ; Tue, 14 Jul 2020 13:46:10.023 +0000 (UTC) Date: Tue, 14 Jul 2020 13:46:10 +0000 (UTC) From: marcandre-ruby-core@marc-andre.ca Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 74956 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Bug X-Redmine-Issue-Id: 17030 X-Redmine-Issue-Author: marcandre X-Redmine-Sender: marcandre X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-SG-EID: =?us-ascii?Q?6=2FIMxCQLDposcQf5wmbDAtfaKduBAO0bKyhL3BGZtMQ5q7K2TvpbN6A7JIyt9E?= =?us-ascii?Q?aOixCr+amwQdGXiT+0pOvWcACDh1FKmjTsGtNxC?= =?us-ascii?Q?nKWml1ifHRGXV6g5pprRrJ8VAVvkfWiUVW5rFVz?= =?us-ascii?Q?nhj6f0bkYnbH8p+XRSWF78XVgkOBnFXSaLM2Mtz?= =?us-ascii?Q?0pg+8Lf+xdjWza7DyFd=2FA7yXficg3fsMDGmsqOt?= =?us-ascii?Q?goKyndjyT9wyhbh+1h6rRhtn1vmLew6jwzrWXz?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 99166 Subject: [ruby-core:99166] [Ruby master Bug#17030] Enumerable#grep{_v} should be optimized for Regexp X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #17030 has been updated by marcandre (Marc-Andre Lafortune). nobu (Nobuyoshi Nakada) wrote in #note-4: > Even without a block, `grep` sets `$~` to the last match result. I agree with @eregon, doesn't seem like it makes much sense to use that. There's also no valid reason it should set `$~` for all the matches tested before the last one. ---------------------------------------- Bug #17030: Enumerable#grep{_v} should be optimized for Regexp https://bugs.ruby-lang.org/issues/17030#change-86544 * 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/