diff --git a/pkg/semantic/version-rubygems.go b/pkg/semantic/version-rubygems.go index 66c6e87f..e75eae51 100644 --- a/pkg/semantic/version-rubygems.go +++ b/pkg/semantic/version-rubygems.go @@ -1,7 +1,6 @@ package semantic import ( - "strconv" "strings" ) @@ -73,11 +72,9 @@ func canonicalSegments(segs []string) (canSegs []string) { } func compareRubyGemsComponents(a, b []string) int { - max := maxInt(len(a), len(b)) + numberOfComponents := maxInt(len(a), len(b)) - var compare int - - for i := 0; i < max; i++ { + for i := 0; i < numberOfComponents; i++ { as := fetch(a, i, "0") bs := fetch(b, i, "0") @@ -86,42 +83,18 @@ func compareRubyGemsComponents(a, b []string) int { switch { case aIsNumber && bIsNumber: - compare = ai.Cmp(bi) + if diff := ai.Cmp(bi); diff != 0 { + return diff + } case !aIsNumber && !bIsNumber: - compare = strings.Compare(as, bs) + if diff := strings.Compare(as, bs); diff != 0 { + return diff + } case aIsNumber: - compare = +1 + return +1 default: - compare = -1 - } - - if compare != 0 { - if compare > 0 { - return 1 - } - - return -1 - } - } - - if len(a) > len(b) { - next := a[len(b)] - - if _, err := strconv.Atoi(next); err == nil { - return 1 - } - - return -1 - } - - if len(a) < len(b) { - next := b[len(a)] - - if _, err := strconv.Atoi(next); err == nil { return -1 } - - return +1 } return 0