tap: optimise CoreTap#formula_files_by_name

This commit is contained in:
Bo Anderson 2023-11-18 01:01:41 +00:00
parent 78b7d7e2d6
commit b1ddb056db
No known key found for this signature in database
GPG Key ID: 3DB94E204E137D65

View File

@ -1138,12 +1138,13 @@ class CoreTap < AbstractCoreTap
def formula_files_by_name
return super if Homebrew::EnvConfig.no_install_from_api?
tap_path = path.to_s
Homebrew::API::Formula.all_formulae.each_with_object({}) do |item, hash|
name, formula_hash = item
# If there's more than one item with the same path: use the longer one to prioritise more specific results.
existing_path = hash[name]
new_path = path/formula_hash["ruby_source_path"]
hash[name] = new_path if existing_path.nil? || existing_path.to_s.length < new_path.to_s.length
new_path = File.join(tap_path, formula_hash["ruby_source_path"]) # Pathname equivalent is slow in a tight loop
hash[name] = Pathname(new_path) if existing_path.nil? || existing_path.to_s.length < new_path.length
end
end
end