Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions src/uucore/src/lib/features/ranges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,17 +245,15 @@ impl Range {
///
/// Is guaranteed to return only disjoint ranges in a sorted order.
pub fn merge(mut ranges: Vec<Self>) -> Vec<Self> {
ranges.sort();

// merge overlapping ranges
for i in 0..ranges.len() {
let j = i + 1;

while j < ranges.len() && ranges[j].low <= ranges[i].high {
let j_high = ranges.remove(j).high;
ranges[i].high = max(ranges[i].high, j_high);
ranges.sort_unstable_by_key(|r| r.low);
ranges.dedup_by(|a, b| {
Comment thread
haydonryan marked this conversation as resolved.
if a.low <= b.high {
b.high = max(b.high, a.high);
true
} else {
false
}
}
});
ranges
}
}
Expand Down
Loading