Accept iterator in universal marker evaluation (#11571)

## Summary

Something I noticed while working on
https://github.com/astral-sh/uv/issues/11548.
This commit is contained in:
Charlie Marsh 2025-02-16 22:29:45 -05:00 committed by GitHub
parent e21f793a1f
commit e95da5c3af
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 20 deletions

View File

@ -1,4 +1,3 @@
use std::borrow::Cow;
use std::collections::hash_map::Entry;
use std::collections::BTreeSet;
use std::collections::VecDeque;
@ -320,17 +319,13 @@ pub trait Installable<'lock> {
additional_activated_extras.push(key);
}
}
let temp_activated_extras = if additional_activated_extras.is_empty() {
Cow::Borrowed(&activated_extras)
} else {
let mut owned = activated_extras.clone();
owned.extend_from_slice(&additional_activated_extras);
Cow::Owned(owned)
};
if !dep.complexified_marker.evaluate(
marker_env,
&temp_activated_extras,
&activated_groups,
activated_extras
.iter()
.chain(additional_activated_extras.iter())
.copied(),
activated_groups.iter().copied(),
) {
continue;
}
@ -413,8 +408,8 @@ pub trait Installable<'lock> {
for dep in deps {
if !dep.complexified_marker.evaluate(
marker_env,
&activated_extras,
&activated_groups,
activated_extras.iter().copied(),
activated_groups.iter().copied(),
) {
continue;
}

View File

@ -245,20 +245,18 @@ impl UniversalMarker {
pub(crate) fn evaluate<P, E, G>(
self,
env: &MarkerEnvironment,
extras: &[(P, E)],
groups: &[(P, G)],
extras: impl Iterator<Item = (P, E)>,
groups: impl Iterator<Item = (P, G)>,
) -> bool
where
P: Borrow<PackageName>,
E: Borrow<ExtraName>,
G: Borrow<GroupName>,
{
let extras = extras
.iter()
.map(|(package, extra)| encode_package_extra(package.borrow(), extra.borrow()));
let groups = groups
.iter()
.map(|(package, group)| encode_package_group(package.borrow(), group.borrow()));
let extras =
extras.map(|(package, extra)| encode_package_extra(package.borrow(), extra.borrow()));
let groups =
groups.map(|(package, group)| encode_package_group(package.borrow(), group.borrow()));
self.marker
.evaluate(env, &extras.chain(groups).collect::<Vec<ExtraName>>())
}