Prevent repeated lookups of nil-valued keys

This commit is contained in:
Jack Nagel 2013-01-08 10:15:57 -06:00
parent dfa387700d
commit c2fd7856d2

View File

@ -20,8 +20,8 @@ module MacOS extend self
# Don't call tools (cc, make, strip, etc.) directly!
# Give the name of the binary you look for as a string to this method
# in order to get the full path back as a Pathname.
@locate ||= {}
@locate[tool.to_s] ||= if File.executable? "/usr/bin/#{tool}"
(@locate ||= {}).fetch(tool.to_s) do
@locate[tool.to_s] = if File.executable? "/usr/bin/#{tool}"
Pathname.new "/usr/bin/#{tool}"
else
# If the tool isn't in /usr/bin, then we first try to use xcrun to find
@ -38,6 +38,7 @@ module MacOS extend self
paths.map { |p| Pathname.new(p) }.find { |p| p.executable? }
end
end
end
def dev_tools_path
@dev_tools_path ||= if File.exist? "/usr/bin/cc" and File.exist? "/usr/bin/make"
@ -64,8 +65,8 @@ module MacOS extend self
end
def sdk_path(v = version)
@sdk_path ||= {}
@sdk_path[v.to_s] ||= begin
(@sdk_path ||= {}).fetch(v.to_s) do
@sdk_path[v.to_s] = begin
opts = []
# First query Xcode itself
opts << `#{locate('xcodebuild')} -version -sdk macosx#{v} Path 2>/dev/null`.chomp unless Xcode.bad_xcode_select_path?
@ -76,6 +77,7 @@ module MacOS extend self
opts.map{|a| Pathname.new(a) }.detect { |p| p.directory? }
end
end
end
def default_cc
cc = locate 'cc'