mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-22 11:22:52 +08:00
Reimplement WGetopter::exchange() using rotate_left
A simplification informed by the new test.
This commit is contained in:
parent
f990d52d2b
commit
ed8f62e723
|
@ -194,36 +194,11 @@ impl<'opts, 'args, 'argarray> WGetopter<'opts, 'args, 'argarray> {
|
|||
/// Elements are then swapped between the list so that all options end up
|
||||
/// in the former list, and non-options in the latter.
|
||||
fn exchange(&mut self) {
|
||||
let mut left = self.first_nonopt;
|
||||
let left = self.first_nonopt;
|
||||
let middle = self.last_nonopt;
|
||||
let mut right = self.wopt_index;
|
||||
let right = self.wopt_index;
|
||||
debug_assert!(left <= middle && middle <= right, "Indexes out of order");
|
||||
|
||||
while right > middle && middle > left {
|
||||
if right - middle > middle - left {
|
||||
// The left segment is the short one.
|
||||
let len = middle - left;
|
||||
|
||||
// Swap it with the top part of the right segment.
|
||||
for i in 0..len {
|
||||
self.argv.swap(left + i, right - len + i);
|
||||
}
|
||||
|
||||
// Exclude the moved elements from further swapping.
|
||||
right -= len;
|
||||
} else {
|
||||
// The right segment is the short one.
|
||||
let len = right - middle;
|
||||
|
||||
// Swap it with the bottom part of the left segment.
|
||||
for i in 0..len {
|
||||
self.argv.swap(left + i, middle + i);
|
||||
}
|
||||
|
||||
// Exclude the moved elements from further swapping.
|
||||
left += len;
|
||||
}
|
||||
}
|
||||
self.argv[left..right].rotate_left(middle - left);
|
||||
|
||||
// Update the indices to indicate the new positions of the non-option
|
||||
// arguments.
|
||||
|
|
Loading…
Reference in New Issue
Block a user