Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add short-circuit exact-match comparison
  • Loading branch information
swagile1 committed Mar 13, 2023
commit d5c8f8aeebb58b00a6679da109225c933f1e7fcf
5 changes: 5 additions & 0 deletions pkg/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ var bigZero = decimal.New(0, 0)
// Versions that differ only by trailing zeros (e.g. "1.2" and "1.2.0") are
// equal.
func Compare(v1, v2 *Version) int {
// if they're the same pointer, the versions are equal
if v1 == v2 {
return 0
}

min, max, longest, flip := minMax(v1.Decimal, v2.Decimal)

// find any difference between these versions where they have the same number of segments
Expand Down