diff options
| author | Jack Nagel | 2014-04-02 20:29:20 -0500 |
|---|---|---|
| committer | Jack Nagel | 2014-04-02 20:29:20 -0500 |
| commit | 3cef191c979622bd938b15353a68394c08fda214 (patch) | |
| tree | 965b7fe00f9ed1b9d189397c08c51296cc745109 /Library/Homebrew/os | |
| parent | 43a692cb88850dd128f8b1daa3b96aa52c5e0821 (diff) | |
| download | homebrew-3cef191c979622bd938b15353a68394c08fda214.tar.bz2 | |
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.
Diffstat (limited to 'Library/Homebrew/os')
| -rw-r--r-- | Library/Homebrew/os/mac/version.rb | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/Library/Homebrew/os/mac/version.rb b/Library/Homebrew/os/mac/version.rb index cfe42a75f..e19ecae70 100644 --- a/Library/Homebrew/os/mac/version.rb +++ b/Library/Homebrew/os/mac/version.rb @@ -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 |
