Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean SemanticVersion for better performance #7234

Merged
merged 1 commit into from
Dec 29, 2018
Merged
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
13 changes: 5 additions & 8 deletions src/semantic_version.cr
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Conforms to Semantic Versioning 2.0.0
#
# See [https://semver.org/](https://semver.org/) for more information.
class SemanticVersion
struct SemanticVersion
include Comparable(self)

# The major version of this semantic version
Expand Down Expand Up @@ -30,8 +30,7 @@ class SemanticVersion
#
# Raises `ArgumentError` if *str* is not a semantic version.
def self.parse(str : String) : self
m = str.match /^(\d+)\.(\d+)\.(\d+)(-([\w\.]+))?(\+(\w+))??$/
if m
if m = str.match /^(\d+)\.(\d+)\.(\d+)(-([\w\.]+))?(\+(\w+))??$/
major = m[1].to_i
minor = m[2].to_i
patch = m[3].to_i
Expand Down Expand Up @@ -118,8 +117,8 @@ class SemanticVersion
def self.parse(str : String) : self
identifiers = [] of String | Int32
str.split('.').each do |val|
if val.match /^\d+$/
identifiers << val.to_i32
if number = val.to_i32?
identifiers << number
else
identifiers << val
end
Expand All @@ -143,7 +142,7 @@ class SemanticVersion
# semver.prerelease.to_s # => "rc.1"
# ```
def to_s(io : IO)
identifiers.join(".", io)
identifiers.join('.', io)
end

# The comparison operator
Expand All @@ -167,8 +166,6 @@ class SemanticVersion
end
elsif other.identifiers.empty?
return -1
else
# continue
end

identifiers.each_with_index do |item, i|
Expand Down