aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew
diff options
context:
space:
mode:
authorJack Nagel2013-04-15 15:00:57 -0500
committerJack Nagel2013-04-15 15:00:57 -0500
commit466a32df02c647b8c4eb268fabacc03526e490d4 (patch)
treedb8d3abc8e3b260dfec847413345832fdff574f4 /Library/Homebrew
parent49682e854d10e99e799e7aeefd1ec08e2ebcf56b (diff)
downloadbrew-466a32df02c647b8c4eb268fabacc03526e490d4.tar.bz2
Optimize Version#<=>
Diffstat (limited to 'Library/Homebrew')
-rw-r--r--Library/Homebrew/version.rb9
1 files changed, 6 insertions, 3 deletions
diff --git a/Library/Homebrew/version.rb b/Library/Homebrew/version.rb
index e504843de..a72c4e617 100644
--- a/Library/Homebrew/version.rb
+++ b/Library/Homebrew/version.rb
@@ -11,6 +11,8 @@ class VersionElement
end
end
+ ZERO = VersionElement.new(0)
+
def <=>(other)
return unless other.is_a? VersionElement
return -1 if string? and other.numeric?
@@ -77,11 +79,12 @@ class Version
return -1 if not head? and other.head?
stuple, otuple = to_a, other.to_a
+ slen, olen = stuple.length, otuple.length
- max = [stuple.length, otuple.length].max
+ max = [slen, olen].max
- stuple.fill(VersionElement.new(0), stuple.length, max - stuple.length)
- otuple.fill(VersionElement.new(0), otuple.length, max - otuple.length)
+ stuple.fill(VersionElement::ZERO, slen, max - slen)
+ otuple.fill(VersionElement::ZERO, olen, max - olen)
stuple <=> otuple
end