Use index instead of current selection (#155)

We can also use `swap_remove` because we're discarding the vector.
This commit is contained in:
Charlie Marsh 2023-10-20 10:02:24 -04:00 committed by GitHub
parent 4645f79237
commit 6f52b5ca4d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -286,7 +286,7 @@ impl<'a> Resolver<'a> {
true
}) else {
// Short circuit: we couldn't find _any_ compatible versions for a package.
let (package, _range) = potential_packages.remove(selection);
let (package, _range) = potential_packages.swap_remove(index);
return Ok((package, None));
};
@ -301,7 +301,7 @@ impl<'a> Resolver<'a> {
// TODO(charlie): This is really ugly, but we need to return `T`, not `&T` (and yet
// we also need to iterate over `potential_packages` multiple times, so we can't
// use `into_iter()`.)
let (package, range) = potential_packages.remove(selection);
let (package, range) = potential_packages.swap_remove(selection);
return match package.borrow() {
PubGrubPackage::Root => Ok((package, Some(MIN_VERSION.clone()))),