Commit ffb007a
committed
🐛 Fix SequenceSet#max(n), cardinality < n <= size
This backports #580 to `v0.5-stable`.
When `SequenceSet#max(n)` is called with `n > cardinality`, it _should_
return a duplicate of the whole set. But, `#max(n)` is implemented
using `#slice(-n..)`, and (copying the behavior of `Array`), when a
slicing starts from an out-of-range index, it returns `nil`.
It was using `-[count, size].min` to keep the index from going
out-of-range. Prior to 0.6.0, `#size` is the same as `#count`, so it
gives incorrect results when the set contains an endless range.
`SequenceSet#cardinality` has not been backported to 0.5, so this makes
that calculation inline.
This change should also give a small performance boost, because it
bypasses the complexity of `#slice(range)` and just calls `#dup` (or
returns `self` when the set is frozen).1 parent 9cf6cfe commit ffb007a
2 files changed
Lines changed: 16 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
755 | 755 | | |
756 | 756 | | |
757 | 757 | | |
758 | | - | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
759 | 765 | | |
760 | 766 | | |
761 | 767 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
787 | 787 | | |
788 | 788 | | |
789 | 789 | | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
790 | 799 | | |
791 | 800 | | |
792 | 801 | | |
| |||
0 commit comments