diff options
| author | Jack Nagel | 2014-04-02 20:29:20 -0500 |
|---|---|---|
| committer | Jack Nagel | 2014-04-02 20:29:20 -0500 |
| commit | c13311ca09062d2c0cf15c51a5071ff8c645bc83 (patch) | |
| tree | 6ca1c4ad67b130f3ff3ba9ac15ee92a811c7cb11 /Library | |
| parent | bb5e0812fb387f2b2a920c9a89e9750fe28943f8 (diff) | |
| download | brew-c13311ca09062d2c0cf15c51a5071ff8c645bc83.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')
| -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 |
