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=-2.7 required=3.0 tests=AWL,BAYES_00, DKIM_ADSP_CUSTOM_MED,FORGED_GMAIL_RCVD,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY shortcircuit=no autolearn=no 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 A7BAB1F4B4 for ; Wed, 30 Sep 2020 16:22:39 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 85DC0120992; Thu, 1 Oct 2020 01:21:49 +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 C00CB12095D for ; Thu, 1 Oct 2020 01:21:46 +0900 (JST) Received: by filterdrecv-p3mdw1-5dd6bc5999-hftd7 with SMTP id filterdrecv-p3mdw1-5dd6bc5999-hftd7-19-5F74B0B4-29 2020-09-30 16:22:12.320661975 +0000 UTC m=+757421.782037360 Received: from herokuapp.com (unknown) by geopod-ismtpd-6-6 (SG) with ESMTP id 3dKr8efMSaehdhosn92RqA for ; Wed, 30 Sep 2020 16:22:12.250 +0000 (UTC) Date: Wed, 30 Sep 2020 16:22:12 +0000 (UTC) From: fatkodima123@gmail.com Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 76082 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Feature X-Redmine-Issue-Id: 17206 X-Redmine-Issue-Author: fatkodima X-Redmine-Sender: fatkodima 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?RvZ0H4gD69HjmyxuoEldmMenU4znNUKl7mOsZIogdq6+UHkw88qRyKjP59Jyuq?= =?us-ascii?Q?RsgS4dZ8075OR2UZm0iTef1qihCZr2k5U7b=2FGCQ?= =?us-ascii?Q?PAOJFLPShEQqsU4B7bG7xNKU=2Fs9cJO3e=2F=2F5evxR?= =?us-ascii?Q?wEzumZMDoknpyX2QMZ30qY2PgCSoPxGHpXwPbLt?= =?us-ascii?Q?XU=2Fbix=2F38Me+JqAun3JWmajRSoqHQxxCbZ2dEdZ?= =?us-ascii?Q?Ywx1diLyRYrC2NxIc=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 100241 Subject: [ruby-core:100241] [Ruby master Feature#17206] Introduce new Regexp option to avoid MatchData allocation 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 #17206 has been updated by fatkodima (Dima Fatko). znz (Kazuhiro NISHIYAMA) wrote in #note-1: > What does `regexp_without_matchdata.match(string)` return when matched? Thats what `when not explicitly needed by the method.` part was about: it returns `MatchData` in this case, as requested. ---------------------------------------- Feature #17206: Introduce new Regexp option to avoid MatchData allocation https://bugs.ruby-lang.org/issues/17206#change-87827 * Author: fatkodima (Dima Fatko) * Status: Open * Priority: Normal ---------------------------------------- Originates from https://bugs.ruby-lang.org/issues/17030 When this option is specified, ruby will not create global `MatchData` objects, when not explicitly needed by the method. If the new option is named `f`, we can write as `/o/f`, and `grep(/o/f)` is faster than `grep(/o/)`. This speeds up not only `grep`, but also `all?`, `any?`, `case` and so on. Many people have written code like this: ```ruby IO.foreach("foo.txt") do |line| case line when /^#/ # do nothing when /^(\d+)/ # using $1 when /xxx/ # using $& when /yyy/ # not using $& else # ... end end ``` This is slow, because of the above mentioned problem. Replacing `/^#/` with `/^#/f`, and `/yyy/` with `/yyy/f` will make it faster. Some benchmarks - https://bugs.ruby-lang.org/issues/17030#note-9 which show `2.5x` to `5x` speedup. PR: https://github.com/ruby/ruby/pull/3455 -- https://bugs.ruby-lang.org/