Commit 02549d9
committed
🐛 Fix SequenceSet#max(n), cardinality < n <= size
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 #564, `#size` was the same as `#count`, so it
would give incorrect results when the set contains an endless range.
After #564, this gives incorrect results when the ordered list contains
duplicates.
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).
This issue was one of the motivations for #563 (and #564), but then I
forgot about the bug, so it wasn't fixed in time for 0.6.0!1 parent 567518c commit 02549d9
File tree
2 files changed
+14
-1
lines changed- lib/net/imap
- test/net/imap
2 files changed
+14
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
788 | 788 | | |
789 | 789 | | |
790 | 790 | | |
791 | | - | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
792 | 796 | | |
793 | 797 | | |
794 | 798 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
808 | 808 | | |
809 | 809 | | |
810 | 810 | | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
811 | 820 | | |
812 | 821 | | |
813 | 822 | | |
| |||
0 commit comments