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-ASN: AS4713 221.184.0.0/13 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 0B0EC1F4B4 for ; Thu, 1 Apr 2021 19:04:37 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id C1C311210D0; Fri, 2 Apr 2021 04:03:32 +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 C54441210CF for ; Fri, 2 Apr 2021 04:03:30 +0900 (JST) Received: by filterdrecv-p3iad2-canary-59c8b5cf-s2mv7 with SMTP id filterdrecv-p3iad2-canary-59c8b5cf-s2mv7-20-60661939-25 2021-04-01 19:04:25.206279982 +0000 UTC m=+782122.748129602 Received: from herokuapp.com (unknown) by ismtpd0193p1mdw1.sendgrid.net (SG) with ESMTP id 2Sqefhx0QKSf4libKTGLaw for ; Thu, 01 Apr 2021 19:04:25.123 +0000 (UTC) Date: Thu, 01 Apr 2021 19:04:25 +0000 (UTC) From: tom.enebo@gmail.com Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 79199 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Feature X-Redmine-Issue-Id: 17771 X-Redmine-Issue-Author: headius X-Redmine-Sender: enebo 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?CEgjm=2FKgaDwZgtms5cDYrJb3X=2F7GsuVdUT8RQZ9PoP3Vbj3wN5U6qKmbH1oCHf?= =?us-ascii?Q?Y8eH3NIZUJQ57fhgZvvHPbYn93bRq8suAQJr0ED?= =?us-ascii?Q?PmfozwegwtlDI7z82yUdtRGNVoGOdTBBzelbK6F?= =?us-ascii?Q?i6ZigutOTiqZU0glzczT5ITok=2FH7o3wVjsSJB1B?= =?us-ascii?Q?M2WdAQAUXzJXbA9U7phgtOUFaO71Lmzg9GbGISO?= =?us-ascii?Q?yXF8gXHVpZ7nfLgoY=3D?= To: ruby-core@ruby-lang.org X-Entity-ID: b/2+PoftWZ6GuOu3b0IycA== X-ML-Name: ruby-core X-Mail-Count: 103156 Subject: [ruby-core:103156] [Ruby master Feature#17771] String#start_with? should not construct MatchData or set $~ 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 #17771 has been updated by enebo (Thomas Enebo). It really feels like an unintended side-effect of the method. If you write this method and accept a variable then depending on the type of that variable there is either some MatchData (MD) as a side-effect or there isn't. This is inconsistent. If you wanted to explicitly use MD then you have to know what you are supplying. If you know it is a regexp then just writing str =~ /^my_pat/ is what you want. ---------------------------------------- Feature #17771: String#start_with? should not construct MatchData or set $~ https://bugs.ruby-lang.org/issues/17771#change-91229 * Author: headius (Charles Nutter) * Status: Open * Priority: Normal ---------------------------------------- I am working on making $~ more thread-safe in JRuby and came across this unexpected behavior: ```ruby $ rvm ruby-3.0 do ruby -e '"foo".start_with?(/foo/); p $~' # ``` The `start_with?` method was added 11 years ago in https://bugs.ruby-lang.org/issues/3388 but I do not think the set of $~ was an intended feature. The `start_with?` method could be much faster and more thread-safe if it did not use the frame-local backref slot and did not allocate a MatchData. Compare with `match?` which was added specifically (without MatchData or backref setting) to provide a fast way to check if a Regexp matches. I propose that `start_with?` stop constructing MatchData, stop setting backref, and provide only its boolean result in the same way as `match?`. -- https://bugs.ruby-lang.org/