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=-3.9 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 365821F4B4 for ; Fri, 25 Sep 2020 06:54:01 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 44BB6120AD1; Fri, 25 Sep 2020 15:53:25 +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 DF66C120AB4 for ; Fri, 25 Sep 2020 15:53:22 +0900 (JST) Received: by filterdrecv-p3las1-6f66587546-tq27l with SMTP id filterdrecv-p3las1-6f66587546-tq27l-20-5F6D9402-40 2020-09-25 06:53:54.677124571 +0000 UTC m=+291319.451151274 Received: from herokuapp.com (unknown) by ismtpd0068p1mdw1.sendgrid.net (SG) with ESMTP id q1mlchIfQgGewm0VVrVxwg for ; Fri, 25 Sep 2020 06:53:54.521 +0000 (UTC) Date: Fri, 25 Sep 2020 06:53:54 +0000 (UTC) From: matz@ruby.or.jp Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 75967 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Bug X-Redmine-Issue-Id: 17030 X-Redmine-Issue-Author: marcandre X-Redmine-Sender: matz 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?bXEIHGfdFwsIlBTndiToCp=2Fmc2rfxRD2sZAksRKJIHWujNEjNjRqosv+I1WXIn?= =?us-ascii?Q?fE+r2faygIZFh=2FDXkBnexn+kZb5OpFzW=2FtvPASY?= =?us-ascii?Q?IP=2FlxLkLnCnPkJC5WEF5wd3ylaoswq0kUwbg1Sx?= =?us-ascii?Q?9622Cy7pGNKWqhNVLkEcdgrIkoJ4MG=2Fa=2FFCnz7Z?= =?us-ascii?Q?T0yuTsWfsdOr0+IkVKafldgfgTmy0ytQvs=2F+OfL?= =?us-ascii?Q?NJk0oVFesdJX=2FV4XI=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 100127 Subject: [ruby-core:100127] [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 matz (Yukihiro Matsumoto). As far as we measured, there are still plenty of room for the optimization (for example, we don't need to allocate `MatchObject` for `grep_v`). We will investigate to improve the performance for those methods. Besides that, `/f` flag for regexp may be a useful idea (though little ugly). Could you resubmit the independent issue for the feature, if you like. Matz. ---------------------------------------- Bug #17030: Enumerable#grep{_v} should be optimized for Regexp https://bugs.ruby-lang.org/issues/17030#change-87696 * 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/