Skip to content

Commit fc9d3da

Browse files
committed
reduce footprint
1 parent 5ecdd72 commit fc9d3da

1 file changed

Lines changed: 11 additions & 18 deletions

File tree

crates/lib/src/hydrate.rs

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ where
4747
let node = graph
4848
.entry(pkg.project.clone())
4949
.or_insert_with(|| Box::new(Node::new(pkg.clone(), None)));
50-
node.pkg.constraint =
51-
intersect_constraints(&node.pkg.constraint, &pkg.constraint, &pkg.project)?;
50+
node.pkg.constraint = intersect_constraints(&node.pkg.constraint, &pkg.constraint)
51+
.map_err(|e| format!("{} for {}", e, pkg.project))?;
5252
stack.push(node.clone());
5353
}
5454

@@ -57,11 +57,8 @@ where
5757
let child_node = graph
5858
.entry(child_pkg.project.clone())
5959
.or_insert_with(|| Box::new(Node::new(child_pkg.clone(), Some(current.clone()))));
60-
let intersection = intersect_constraints(
61-
&child_node.pkg.constraint,
62-
&child_pkg.constraint,
63-
&child_pkg.project,
64-
);
60+
let intersection =
61+
intersect_constraints(&child_node.pkg.constraint, &child_pkg.constraint);
6562
if let Ok(constraint) = intersection {
6663
child_node.pkg.constraint = constraint;
6764
current.children.insert(child_node.pkg.project.clone());
@@ -72,7 +69,9 @@ where
7269
// https://github.com/pkgxdev/pkgx/issues/899
7370
additional_unicodes.push(child_pkg.constraint);
7471
} else {
75-
return Err(intersection.unwrap_err());
72+
return Err(
73+
format!("{} for {}", intersection.unwrap_err(), child_pkg.project).into(),
74+
);
7675
}
7776
}
7877
}
@@ -98,9 +97,8 @@ fn condense(pkgs: &Vec<PackageReq>) -> Vec<PackageReq> {
9897
let mut out: Vec<PackageReq> = vec![];
9998
for pkg in pkgs {
10099
if let Some(existing) = out.iter_mut().find(|p| p.project == pkg.project) {
101-
existing.constraint =
102-
intersect_constraints(&existing.constraint, &pkg.constraint, &pkg.project)
103-
.expect("Failed to intersect constraints");
100+
existing.constraint = intersect_constraints(&existing.constraint, &pkg.constraint)
101+
.expect("Failed to intersect constraints");
104102
} else {
105103
out.push(pkg.clone());
106104
}
@@ -109,11 +107,6 @@ fn condense(pkgs: &Vec<PackageReq>) -> Vec<PackageReq> {
109107
}
110108

111109
/// Intersects two version constraints.
112-
fn intersect_constraints(
113-
a: &VersionReq,
114-
b: &VersionReq,
115-
project_name: &str,
116-
) -> Result<VersionReq, Box<dyn Error>> {
117-
a.intersect(b)
118-
.map_err(|e| format!("{} for {}: {} and {}", e, project_name, a, b).into())
110+
fn intersect_constraints(a: &VersionReq, b: &VersionReq) -> Result<VersionReq, Box<dyn Error>> {
111+
a.intersect(b).map_err(|e| e.into())
119112
}

0 commit comments

Comments
 (0)