Skip to content

Commit 9b73182

Browse files
committed
intern links attribute
1 parent 6535475 commit 9b73182

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

src/cargo/core/interning.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::fmt;
12
use std::sync::RwLock;
23
use std::collections::HashSet;
34
use std::slice;
@@ -51,6 +52,13 @@ impl Deref for InternedString {
5152
}
5253
}
5354

55+
impl fmt::Debug for InternedString {
56+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
57+
let str: &str = &*self;
58+
write!(f, "InternedString {{ {} }}", str)
59+
}
60+
}
61+
5462
impl Ord for InternedString {
5563
fn cmp(&self, other: &InternedString) -> Ordering {
5664
let str: &str = &*self;

src/cargo/core/resolver/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -734,11 +734,11 @@ impl RemainingCandidates {
734734
use std::mem::replace;
735735
for (_, b) in self.remaining.by_ref() {
736736
if let Some(link) = b.summary.links() {
737-
if let Some(a) = links.get(&InternedString::new(link)) {
737+
if let Some(a) = links.get(&link) {
738738
if a != b.summary.package_id() {
739739
self.conflicting_prev_active
740740
.entry(a.clone())
741-
.or_insert_with(|| ConflictReason::Links(link.to_owned()));
741+
.or_insert_with(|| ConflictReason::Links(link.to_string()));
742742
continue;
743743
}
744744
}
@@ -1309,9 +1309,9 @@ impl Context {
13091309
if !prev.iter().any(|c| c == summary) {
13101310
self.resolve_graph.push(GraphNode::Add(id.clone()));
13111311
if let Some(link) = summary.links() {
1312-
ensure!(self.links.insert(InternedString::new(link), id.clone()).is_none(),
1312+
ensure!(self.links.insert(link, id.clone()).is_none(),
13131313
"Attempting to resolve a with more then one crate with the links={}. \n\
1314-
This will not build as is. Consider rebuilding the .lock file.", link);
1314+
This will not build as is. Consider rebuilding the .lock file.", &*link);
13151315
}
13161316
let mut inner: Vec<_> = (**prev).clone();
13171317
inner.push(summary.clone());

src/cargo/core/summary.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::rc::Rc;
44

55
use semver::Version;
66
use core::{Dependency, PackageId, SourceId};
7+
use core::interning::InternedString;
78

89
use util::CargoResult;
910

@@ -22,7 +23,7 @@ struct Inner {
2223
dependencies: Vec<Dependency>,
2324
features: BTreeMap<String, Vec<String>>,
2425
checksum: Option<String>,
25-
links: Option<String>,
26+
links: Option<InternedString>,
2627
}
2728

2829
impl Summary {
@@ -71,7 +72,7 @@ impl Summary {
7172
dependencies,
7273
features,
7374
checksum: None,
74-
links,
75+
links: links.map(|l| InternedString::new(&l)),
7576
}),
7677
})
7778
}
@@ -85,8 +86,8 @@ impl Summary {
8586
pub fn checksum(&self) -> Option<&str> {
8687
self.inner.checksum.as_ref().map(|s| &s[..])
8788
}
88-
pub fn links(&self) -> Option<&str> {
89-
self.inner.links.as_ref().map(|s| &s[..])
89+
pub fn links(&self) -> Option<InternedString> {
90+
self.inner.links
9091
}
9192

9293
pub fn override_id(mut self, id: PackageId) -> Summary {

0 commit comments

Comments
 (0)