Skip to content

Commit f2b4998

Browse files
committed
reorder ActivationKey so that the source is last
The source is the field the most expensive to do Eq on and the one least likely to be different. By moving it to the end calles to comparing keys that are different returns faster.
1 parent a699239 commit f2b4998

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/cargo/core/resolver/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ impl ResolverContext {
107107
if let Some((_, dep)) = parent {
108108
if dep.source_id() != id.source_id() {
109109
let key =
110-
ActivationsKey::new(id.name(), dep.source_id(), id.version().into());
110+
ActivationsKey::new(id.name(), id.version().into(), dep.source_id());
111111
let prev = self.activations.insert(key, (summary.clone(), age));
112112
if let Some((previous_summary, _)) = prev {
113113
return Err(

src/cargo/core/resolver/types.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,11 @@ impl ResolveOpts {
168168
/// semver compatible version of each crate.
169169
/// Find the activated version of a crate based on the name, source, and semver compatibility.
170170
#[derive(Clone, PartialEq, Eq, Debug, Ord, PartialOrd, Hash)]
171-
pub struct ActivationsKey(InternedString, SourceId, SemverCompatibility);
171+
pub struct ActivationsKey(InternedString, SemverCompatibility, SourceId);
172172

173173
impl ActivationsKey {
174-
pub fn new(name: InternedString, source_id: SourceId, ver: SemverCompatibility) -> ActivationsKey {
175-
ActivationsKey(name, source_id, ver)
174+
pub fn new(name: InternedString, ver: SemverCompatibility, source_id: SourceId) -> ActivationsKey {
175+
ActivationsKey(name, ver, source_id)
176176
}
177177
}
178178

@@ -200,7 +200,7 @@ impl From<&semver::Version> for SemverCompatibility {
200200

201201
impl PackageId {
202202
pub fn as_activations_key(self) -> ActivationsKey {
203-
ActivationsKey(self.name(), self.source_id(), self.version().into())
203+
ActivationsKey(self.name(), self.version().into(), self.source_id())
204204
}
205205
}
206206

0 commit comments

Comments
 (0)