aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJack Nagel2014-07-13 10:50:56 -0500
committerJack Nagel2014-07-13 10:50:56 -0500
commitfe366ef251423a1946bb665243f3b92afaffc56c (patch)
treec83356a724cc204b15c79c325e6c8a94b216de26
parentb9cd667edb3ab7bdc11e27d2542bfb76e1e054ea (diff)
downloadhomebrew-fe366ef251423a1946bb665243f3b92afaffc56c.tar.bz2
Use a hash to cache compiler version lookups
-rw-r--r--Library/Homebrew/os/mac.rb16
1 files changed, 6 insertions, 10 deletions
diff --git a/Library/Homebrew/os/mac.rb b/Library/Homebrew/os/mac.rb
index e896901ed..6deea1d0f 100644
--- a/Library/Homebrew/os/mac.rb
+++ b/Library/Homebrew/os/mac.rb
@@ -121,16 +121,12 @@ module OS
end
def non_apple_gcc_version(cc)
- path = HOMEBREW_PREFIX.join("opt/gcc/bin/#{cc}")
- path = nil unless path.exist?
-
- return unless path ||= locate(cc)
-
- ivar = "@#{cc.gsub(/(-|\.)/, '')}_version"
- return instance_variable_get(ivar) if instance_variable_defined?(ivar)
-
- `#{path} --version` =~ /gcc(-\d\.\d \(.+\))? (\d\.\d\.\d)/
- instance_variable_set(ivar, $2)
+ (@non_apple_gcc_version ||= {}).fetch(cc) do
+ path = HOMEBREW_PREFIX.join("opt", "gcc", "bin", cc)
+ path = locate(cc) unless path.exist?
+ version = %x{#{path} --version}[/gcc(?:-\d\.\d \(.+\))? (\d\.\d\.\d)/, 1] if path
+ @non_apple_gcc_version[cc] = version
+ end
end
# See these issues for some history: