Skip to content

Commit

Permalink
Replace PackageId::wrap with PackageId::pure
Browse files Browse the repository at this point in the history
  • Loading branch information
dwijnand committed Dec 22, 2018
1 parent cffd5b2 commit 1606ab3
Showing 1 changed file with 15 additions and 22 deletions.
37 changes: 15 additions & 22 deletions src/cargo/core/package_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ impl<'de> de::Deserialize<'de> for PackageId {
let string = String::deserialize(d)?;
let mut s = string.splitn(3, ' ');
let name = s.next().unwrap();
let name = InternedString::new(name);
let version = match s.next() {
Some(s) => s,
None => return Err(de::Error::custom("invalid serialized PackageId")),
Expand All @@ -88,11 +89,7 @@ impl<'de> de::Deserialize<'de> for PackageId {
};
let source_id = SourceId::from_url(url).map_err(de::Error::custom)?;

Ok(PackageId::wrap(PackageIdInner {
name: InternedString::new(name),
version,
source_id,
}))
Ok(PackageId::pure(name, version, source_id))
}
}

Expand All @@ -118,15 +115,15 @@ impl<'a> Hash for PackageId {
impl PackageId {
pub fn new<T: ToSemver>(name: &str, version: T, sid: SourceId) -> CargoResult<PackageId> {
let v = version.to_semver()?;

Ok(PackageId::wrap(PackageIdInner {
name: InternedString::new(name),
version: v,
source_id: sid,
}))
Ok(PackageId::pure(InternedString::new(name), v, sid))
}

fn wrap(inner: PackageIdInner) -> PackageId {
pub fn pure(name: InternedString, version: semver::Version, source_id: SourceId) -> PackageId {
let inner = PackageIdInner {
name,
version,
source_id,
};
let mut cache = PACKAGE_ID_CACHE.lock().unwrap();
let inner = cache.get(&inner).cloned().unwrap_or_else(|| {
let inner = Box::leak(Box::new(inner));
Expand All @@ -147,19 +144,15 @@ impl PackageId {
}

pub fn with_precise(self, precise: Option<String>) -> PackageId {
PackageId::wrap(PackageIdInner {
name: self.inner.name,
version: self.inner.version.clone(),
source_id: self.inner.source_id.with_precise(precise),
})
PackageId::pure(
self.inner.name,
self.inner.version.clone(),
self.inner.source_id.with_precise(precise),
)
}

pub fn with_source_id(self, source: SourceId) -> PackageId {
PackageId::wrap(PackageIdInner {
name: self.inner.name,
version: self.inner.version.clone(),
source_id: source,
})
PackageId::pure(self.inner.name, self.inner.version.clone(), source)
}

pub fn stable_hash(self, workspace: &Path) -> PackageIdStableHash<'_> {
Expand Down

0 comments on commit 1606ab3

Please sign in to comment.