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.
This commit is contained in:
parent
bb5e0812fb
commit
c13311ca09
@ -16,9 +16,16 @@ module OS
|
|||||||
new(SYMBOLS.fetch(sym))
|
new(SYMBOLS.fetch(sym))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def initialize(*args)
|
||||||
|
super
|
||||||
|
@comparison_cache = {}
|
||||||
|
end
|
||||||
|
|
||||||
def <=>(other)
|
def <=>(other)
|
||||||
|
@comparison_cache.fetch(other) do
|
||||||
v = SYMBOLS.fetch(other, other.to_s)
|
v = SYMBOLS.fetch(other, other.to_s)
|
||||||
super(Version.new(v))
|
@comparison_cache[other] = super(Version.new(v))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_sym
|
def to_sym
|
||||||
|
Loading…
x
Reference in New Issue
Block a user