Remove InMemoryIndexRef (#4544)

`InMemoryIndex` has recently been turned into an `Arc`, so we can now
freely copy it instead using `Cow` tricks.
This commit is contained in:
konsti 2024-06-26 15:11:14 +02:00 committed by GitHub
parent 9701ead5be
commit 2ef34bd65b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,6 +1,5 @@
use std::env; use std::env;
use std::io::stdout; use std::io::stdout;
use std::ops::Deref;
use std::path::Path; use std::path::Path;
use anstream::{eprint, AutoStream, StripStream}; use anstream::{eprint, AutoStream, StripStream};
@ -207,9 +206,9 @@ pub(crate) async fn pip_compile(
// distributions will be built against the installed version, and so the index may contain // distributions will be built against the installed version, and so the index may contain
// different package priorities than in the top-level resolution. // different package priorities than in the top-level resolution.
let top_level_index = if python_version.is_some() { let top_level_index = if python_version.is_some() {
InMemoryIndexRef::Owned(InMemoryIndex::default()) InMemoryIndex::default()
} else { } else {
InMemoryIndexRef::Borrowed(&source_index) source_index.clone()
}; };
// Determine the Python requirement, if the user requested a specific version. // Determine the Python requirement, if the user requested a specific version.
@ -597,20 +596,3 @@ impl OutputWriter {
Ok(()) Ok(())
} }
} }
/// An owned or unowned [`InMemoryIndex`].
enum InMemoryIndexRef<'a> {
Owned(InMemoryIndex),
Borrowed(&'a InMemoryIndex),
}
impl Deref for InMemoryIndexRef<'_> {
type Target = InMemoryIndex;
fn deref(&self) -> &Self::Target {
match self {
Self::Owned(index) => index,
Self::Borrowed(index) => index,
}
}
}