From b1ddb056db1fd65f094de80a228d81cdd43e5958 Mon Sep 17 00:00:00 2001 From: Bo Anderson Date: Sat, 18 Nov 2023 01:01:41 +0000 Subject: [PATCH] tap: optimise `CoreTap#formula_files_by_name` --- Library/Homebrew/tap.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/tap.rb b/Library/Homebrew/tap.rb index 96ab6bf340..5512133cd0 100644 --- a/Library/Homebrew/tap.rb +++ b/Library/Homebrew/tap.rb @@ -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