Skip to content
Snippets Groups Projects
Commit 5bf652ec authored by Jack Nagel's avatar Jack Nagel
Browse files

Avoid extra array allocations

parent b3220203
No related branches found
No related tags found
No related merge requests found
......@@ -106,13 +106,16 @@ class Options
when self then arg
when Option then new << arg
when Array
opts = arg.map do |_arg|
case _arg
when /^-[^-]+$/ then _arg[1..-1].split(//)
else _arg
opts = new
arg.each do |a|
case a
when /^-[^-]+$/
a[1..-1].split(//).each { |o| opts << Option.new(o) }
else
opts << Option.new(a)
end
end.flatten
new(opts.map { |o| Option.new(o) })
end
opts
else
raise TypeError, "Cannot convert #{arg.inspect} to Options"
end
......
......@@ -97,7 +97,7 @@ class Version
protected
def to_a
@array ||= @version.scan(/\d+|[a-zA-Z]+/).map { |e| VersionElement.new(e) }
@array ||= @version.scan(/\d+|[a-zA-Z]+/).map! { |e| VersionElement.new(e) }
end
def self.parse spec
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment