mirror of
https://github.com/astral-sh/uv.git
synced 2025-10-27 18:36:44 +00:00
pep508: some simplification in 'and' and 'or'
Basically, and'ing or or'ing the same expression can be entire skipped. And we try harder to avoid singleton conjunctions or disjunctions, as these are considered unequal otherwise. (Thus defeating our attempts to avoid and'ing or or'ing a superfluous marker.)
This commit is contained in:
parent
8b8f34ac21
commit
7fce59e4bc
1 changed files with 12 additions and 0 deletions
|
|
@ -1105,6 +1105,9 @@ impl MarkerTree {
|
|||
/// already, then `tree` is added to it instead of creating a new
|
||||
/// conjunction.
|
||||
pub fn and(&mut self, tree: MarkerTree) {
|
||||
if self == &tree {
|
||||
return;
|
||||
}
|
||||
match *self {
|
||||
MarkerTree::Expression(_) | MarkerTree::Or(_) => {
|
||||
let this = std::mem::replace(self, MarkerTree::And(vec![]));
|
||||
|
|
@ -1118,6 +1121,9 @@ impl MarkerTree {
|
|||
} else {
|
||||
exprs.push(tree);
|
||||
}
|
||||
if exprs.len() == 1 {
|
||||
*self = exprs.pop().unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1127,6 +1133,9 @@ impl MarkerTree {
|
|||
/// already, then `tree` is added to it instead of creating a new
|
||||
/// disjunction.
|
||||
pub fn or(&mut self, tree: MarkerTree) {
|
||||
if self == &tree {
|
||||
return;
|
||||
}
|
||||
match *self {
|
||||
MarkerTree::Expression(_) | MarkerTree::And(_) => {
|
||||
let this = std::mem::replace(self, MarkerTree::And(vec![]));
|
||||
|
|
@ -1140,6 +1149,9 @@ impl MarkerTree {
|
|||
} else {
|
||||
exprs.push(tree);
|
||||
}
|
||||
if exprs.len() == 1 {
|
||||
*self = exprs.pop().unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue