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.6 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_HELO_NONE,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 47A5F1F462 for ; Sun, 16 Jun 2019 13:26:57 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 15751120BC9; Sun, 16 Jun 2019 22:26:51 +0900 (JST) Received: from o1678916x28.outbound-mail.sendgrid.net (o1678916x28.outbound-mail.sendgrid.net [167.89.16.28]) by neon.ruby-lang.org (Postfix) with ESMTPS id D3BA8120BC9 for ; Sun, 16 Jun 2019 22:26:48 +0900 (JST) Received: by filter0057p3iad2.sendgrid.net with SMTP id filter0057p3iad2-7780-5D064399-4 2019-06-16 13:26:49.112459236 +0000 UTC m=+1024799.590777186 Received: from herokuapp.com (unknown [3.84.21.142]) by ismtpd0002p1iad1.sendgrid.net (SG) with ESMTP id mYmrDdggS3Ww9KKAc2_L1A for ; Sun, 16 Jun 2019 13:26:48.880 +0000 (UTC) Date: Sun, 16 Jun 2019 13:26:49 +0000 (UTC) From: janosch84@gmail.com Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 68667 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+mR02klozhrfvpSZLLM+XAfHbuoTMo3kkm9S?= =?us-ascii?Q?iGUha4HQ+EiOZ=2FadM8pC0ASq5BeWGCtSmcUWxeS?= =?us-ascii?Q?DyQc9QqwuvKIma1IZN=2FFyRpPQeCotuEwKFvD4Ch?= =?us-ascii?Q?fgVDL8Uaim+9CFCvZdEMXUZKhPRU5P+q6aQ7qwo?= =?us-ascii?Q?bZtWD2VnbZc3ARVLvIBzQBT0e8ZXzB4IUFA=3D=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 93181 Subject: [ruby-core:93181] [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). Thinking about this a bit more generally, I'm wondering whether `Enumerable= #minmax` should actually use `rb_funcall` to get `min` and `max`. This would fix the problem described in this issue. But perhaps more importantly, it eliminates the trap of forgetting to imple= ment `#minmax` whenever you override `#min` and/or `#max`. Right now, `#minmax` is effectively broken for every case where `#min` and/= or `#max` is overridden to optimize performance, to use custom checks, or t= o return a custom value -- unless `#minmax` is also overridden with `def mi= nmax; [min, max] end`. As `Range` shows, arguably even ruby core coders have fallen into this trap= ... ---------------------------------------- Bug #15807: Range#minmax is slow and never returns for endless ranges https://bugs.ruby-lang.org/issues/15807#change-78622 * 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! ---Files-------------------------------- range-minmax.patch (2.89 KB) -- = https://bugs.ruby-lang.org/ Unsubscribe: