Avoid extra array allocations
This commit is contained in:
parent
b322020338
commit
5bf652ecdd
@ -106,13 +106,16 @@ class Options
|
|||||||
when self then arg
|
when self then arg
|
||||||
when Option then new << arg
|
when Option then new << arg
|
||||||
when Array
|
when Array
|
||||||
opts = arg.map do |_arg|
|
opts = new
|
||||||
case _arg
|
arg.each do |a|
|
||||||
when /^-[^-]+$/ then _arg[1..-1].split(//)
|
case a
|
||||||
else _arg
|
when /^-[^-]+$/
|
||||||
|
a[1..-1].split(//).each { |o| opts << Option.new(o) }
|
||||||
|
else
|
||||||
|
opts << Option.new(a)
|
||||||
end
|
end
|
||||||
end.flatten
|
end
|
||||||
new(opts.map { |o| Option.new(o) })
|
opts
|
||||||
else
|
else
|
||||||
raise TypeError, "Cannot convert #{arg.inspect} to Options"
|
raise TypeError, "Cannot convert #{arg.inspect} to Options"
|
||||||
end
|
end
|
||||||
|
|||||||
@ -97,7 +97,7 @@ class Version
|
|||||||
protected
|
protected
|
||||||
|
|
||||||
def to_a
|
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
|
end
|
||||||
|
|
||||||
def self.parse spec
|
def self.parse spec
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user