diff --git a/src/identifier.rs b/src/identifier.rs index 74a5ce7f..c7fb1c9a 100644 --- a/src/identifier.rs +++ b/src/identifier.rs @@ -257,12 +257,18 @@ impl Drop for Identifier { } } +impl Identifier { + pub(crate) fn ptr_eq(&self, rhs: &Self) -> bool { + self.head == rhs.head && self.tail == rhs.tail + } +} + impl PartialEq for Identifier { fn eq(&self, rhs: &Self) -> bool { - if self.is_empty_or_inline() { + if self.ptr_eq(rhs) { // Fast path (most common) - self.head == rhs.head && self.tail == rhs.tail - } else if rhs.is_empty_or_inline() { + true + } else if self.is_empty_or_inline() || rhs.is_empty_or_inline() { false } else { // SAFETY: both reprs are in the heap allocated representation. diff --git a/src/impls.rs b/src/impls.rs index cc4fd415..24d7d281 100644 --- a/src/impls.rs +++ b/src/impls.rs @@ -50,8 +50,10 @@ impl PartialOrd for BuildMetadata { impl Ord for Prerelease { fn cmp(&self, rhs: &Self) -> Ordering { + if self.identifier.ptr_eq(&rhs.identifier) { + return Ordering::Equal; + } match self.is_empty() { - true if rhs.is_empty() => return Ordering::Equal, // A real release compares greater than prerelease. true => return Ordering::Greater, // Prerelease compares less than the real release. @@ -105,6 +107,9 @@ impl Ord for Prerelease { impl Ord for BuildMetadata { fn cmp(&self, rhs: &Self) -> Ordering { + if self.identifier.ptr_eq(&rhs.identifier) { + return Ordering::Equal; + } let lhs = self.as_str().split('.'); let mut rhs = rhs.as_str().split('.');