From 237fa3164dcb56f6de3b875ed9fe9b47c7b0712b Mon Sep 17 00:00:00 2001 From: Jack Nagel Date: Sun, 13 Jul 2014 10:50:56 -0500 Subject: [PATCH] Use a hash to cache compiler version lookups --- Library/Homebrew/os/mac.rb | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/Library/Homebrew/os/mac.rb b/Library/Homebrew/os/mac.rb index e896901edd..6deea1d0f1 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: