Skip to content

Commit d2d2102

Browse files
committed
dont call wrap in a no-op source_id::with*
1 parent a7c4206 commit d2d2102

File tree

1 file changed

+33
-16
lines changed

1 file changed

+33
-16
lines changed

src/cargo/core/source_id.rs

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -468,34 +468,51 @@ impl SourceId {
468468

469469
/// Creates a new `SourceId` from this source with the given `precise`.
470470
pub fn with_git_precise(self, fragment: Option<String>) -> SourceId {
471-
SourceId::wrap(SourceIdInner {
472-
precise: fragment.map(|f| Precise::GitUrlFragment(f)),
473-
..(*self.inner).clone()
474-
})
471+
let precise = fragment.map(|f| Precise::GitUrlFragment(f));
472+
if self.inner.precise == precise {
473+
self
474+
} else {
475+
SourceId::wrap(SourceIdInner {
476+
precise,
477+
..(*self.inner).clone()
478+
})
479+
}
475480
}
476481

477482
/// Creates a new `SourceId` from this source without a `precise`.
478483
pub fn without_precise(self) -> SourceId {
479-
SourceId::wrap(SourceIdInner {
480-
precise: None,
481-
..(*self.inner).clone()
482-
})
484+
if self.inner.precise.is_none() {
485+
self
486+
} else {
487+
SourceId::wrap(SourceIdInner {
488+
precise: None,
489+
..(*self.inner).clone()
490+
})
491+
}
483492
}
484493

485494
/// Creates a new `SourceId` from this source without a `precise`.
486495
pub fn with_locked_precise(self) -> SourceId {
487-
SourceId::wrap(SourceIdInner {
488-
precise: Some(Precise::Locked),
489-
..(*self.inner).clone()
490-
})
496+
if self.inner.precise == Some(Precise::Locked) {
497+
self
498+
} else {
499+
SourceId::wrap(SourceIdInner {
500+
precise: Some(Precise::Locked),
501+
..(*self.inner).clone()
502+
})
503+
}
491504
}
492505

493506
/// Creates a new `SourceId` from this source with the `precise` from some other `SourceId`.
494507
pub fn with_precise_from(self, v: Self) -> SourceId {
495-
SourceId::wrap(SourceIdInner {
496-
precise: v.inner.precise.clone(),
497-
..(*self.inner).clone()
498-
})
508+
if self.inner.precise == v.inner.precise {
509+
self
510+
} else {
511+
SourceId::wrap(SourceIdInner {
512+
precise: v.inner.precise.clone(),
513+
..(*self.inner).clone()
514+
})
515+
}
499516
}
500517

501518
/// When updating a lock file on a version using `cargo update --precise`

0 commit comments

Comments
 (0)