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.9 required=3.0 tests=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_PASS 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 C88871F453 for ; Sun, 28 Apr 2019 14:29:57 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 52E621209E2; Sun, 28 Apr 2019 23:29:52 +0900 (JST) Received: from o1678948x4.outbound-mail.sendgrid.net (o1678948x4.outbound-mail.sendgrid.net [167.89.48.4]) by neon.ruby-lang.org (Postfix) with ESMTPS id C61381209C4 for ; Sun, 28 Apr 2019 23:29:49 +0900 (JST) Received: by filter0057p3mdw1.sendgrid.net with SMTP id filter0057p3mdw1-32438-5CC5B8DE-A 2019-04-28 14:29:50.266701438 +0000 UTC m=+237669.735119455 Received: from herokuapp.com (unknown [54.91.45.152]) by ismtpd0048p1mdw1.sendgrid.net (SG) with ESMTP id Xl46Y3blRqKoduOps59FvQ for ; Sun, 28 Apr 2019 14:29:50.181 +0000 (UTC) Date: Sun, 28 Apr 2019 14:29:50 +0000 (UTC) From: janosch84@gmail.com Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 67946 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 15807 X-Redmine-Issue-Author: janosch-x X-Redmine-Sender: janosch-x 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?0k5sXJRcmdpWYfOD1oWBjpTENp+mR02klozhrfvpSZJTtHXgVoXArgTU9haHP3?= =?us-ascii?Q?g9+0NGsZg8I4Ie8ReTgrLSGOYDrEZe=2FRlFLRnKU?= =?us-ascii?Q?8f8aySWQvUdOQF66dIJnBO7IuhlkZRk0tGLaapl?= =?us-ascii?Q?Ys1KJlQ9iT7OOFpe3xFRz=2FWqGc+K41t+7VboHoZ?= =?us-ascii?Q?QMMpYES4Cr+M8gZ+cg9VBkb=2F6gy=2FMTXw7Nw=3D=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 92463 Subject: [ruby-core:92463] [Ruby trunk Bug#15807] Range#minmax is slow and never returns for endless ranges 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="iso-8859-1" Content-Transfer-Encoding: quoted-printable Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #15807 has been updated by janosch-x (Janosch M=FCller). mame (Yusuke Endoh) wrote: > `Range#max` is not consistent with `Enumerable#minmax`. Thanks for pointing this out, I wasn't aware of that. Floats are another ex= ample: ``` ruby (1..(5.5)).max # =3D> 5.5 (1..(5.5)).minmax # =3D> [1, 5] ``` Maybe we could fix / speedup `minmax` only for ranges where `begin` and `en= d` are `NIL_P`/`is_integer_p`/`Float::INFINITY`, and call super for all oth= er cases? A check for `Float::INFINITY` might be helpful here, too, while we're at it= : https://github.com/ruby/ruby/blob/ae6c195f30f76b1dc4a32a0a91d35fe80f6f85d= 3/range.c#L808 My use case has to do with Regexp quantification. I can go into more detail= , but to describe it quickly, I want to provide information about how many = chars a Regexp can match in https://github.com/ammar/regexp_parser. Ranges,= some ending with Infinity, are the most natural choice for this, but minma= x would be useful in the related code. Also, I don't want to hand out "dang= erous" Ranges to gem users. Maybe I will `#extend` the Ranges with a safe m= inmax. ---------------------------------------- Bug #15807: Range#minmax is slow and never returns for endless ranges https://bugs.ruby-lang.org/issues/15807#change-77812 * Author: janosch-x (Janosch M=FCller) * Status: Open * Priority: Normal * Assignee: = * Target version: = * ruby -v: 2.6.3p62 * Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN ---------------------------------------- current situation: - `(1..).minmax` runs forever - `(1..).max` raises "cannot get the maximum of endless range" - `(1..Float::INFINITY).minmax` runs forever - `(1..Float::INFINITY).max` returns instantly - `(1..1_000_000_000).minmax` takes one minute - `(1..1_000_000_000).max` returns instantly my suggestion: - implement `minmax` in range.c, return [`range_min`, `range_max`] - for endless ranges, this will trigger the same error as `max` does - delegate to enum (rb_call_super) only if called with a block (?) i could perhaps provide a PR if you can point me to some information on how= to contribute. cheers! -- = https://bugs.ruby-lang.org/ Unsubscribe: