[ruby-core:93021] [Ruby trunk Bug#15807] Range#minmax is slow and never returns for endless ranges

From: merch-redmine@...
Date: 2019-06-08 05:24:07 UTC
List: ruby-core #93021
Issue #15807 has been updated by jeremyevans0 (Jeremy Evans).

File range-minmax.patch added

I think this is a bug we should fix, even if it breaks code relying on this bug ("all bug fixes are incompatibilities" :)).

I worked on a patch for #15867, before realizing mohsen created a pull request for this.  My patch ended up being very similar to mohsen's, it is attached.  The main differences are that my patch calls `range_min`/`range_max` C functions directly instead of calling `min` and `max` using `rb_funcall`, and mohsen's patch includes tests and specs, and mine only tests.

Does anyone have an opinion on whether `minmax` should call overridden `min` and `max` methods?  Or do we expect if you override `min` or `max`, you should also override `minmax`?  I don't have a strong opinion either way.

----------------------------------------
Bug #15807: Range#minmax is slow and never returns for endless ranges
https://bugs.ruby-lang.org/issues/15807#change-78397

* Author: janosch-x (Janosch Mler)
* 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: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread

Prev Next