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

Cache MacOS.version comparison results

MacOS.version#<=> is called many, many times during formula loading with
the same half dozen or so arguments. A typical call to this method
involves:

 * a hash lookup to convert a symbol argument to a string
 * creation of a throw-away Version object wrapping the argument
 * the actual version comparison, which is not cheap

This makes it a prime candidate to be memoized.
parent bb5e0812
No related branches found
No related tags found
No related merge requests found
......@@ -16,9 +16,16 @@ module OS
new(SYMBOLS.fetch(sym))
end
def initialize(*args)
super
@comparison_cache = {}
end
def <=>(other)
v = SYMBOLS.fetch(other, other.to_s)
super(Version.new(v))
@comparison_cache.fetch(other) do
v = SYMBOLS.fetch(other, other.to_s)
@comparison_cache[other] = super(Version.new(v))
end
end
def to_sym
......
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