From 0592f7ac072c0b104d081eb617d66fd30875ec5f Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Fri, 23 Feb 2024 15:05:52 +0100 Subject: [PATCH 1/2] Simplify `Tap#alias_table`. --- Library/Homebrew/tap.rb | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/Library/Homebrew/tap.rb b/Library/Homebrew/tap.rb index c3fbc5f733..4396e3ea9e 100644 --- a/Library/Homebrew/tap.rb +++ b/Library/Homebrew/tap.rb @@ -150,7 +150,6 @@ class Tap @full_name = "#{@user}/homebrew-#{@repo}" @path = TAP_DIRECTORY/@full_name.downcase @git_repo = GitRepository.new(@path) - @alias_table = nil @alias_reverse_table = nil end @@ -715,17 +714,14 @@ class Tap @aliases ||= alias_table.keys end - # a table mapping alias to formula name + # Mapping from aliases to formula names. + # # @private sig { returns(T::Hash[String, String]) } def alias_table - return @alias_table if @alias_table - - @alias_table = {} - alias_files.each do |alias_file| - @alias_table[alias_file_to_name(alias_file)] = formula_file_to_name(alias_file.resolved_path) + @alias_table ||= alias_files.each_with_object({}) do |alias_file, alias_table| + alias_table[alias_file_to_name(alias_file)] = formula_file_to_name(alias_file.resolved_path) end - @alias_table end # a table mapping formula name to aliases From 890bec6515abe7db999b353dbfa300889ac7e759 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Fri, 23 Feb 2024 15:06:36 +0100 Subject: [PATCH 2/2] Simplify `Tap#alias_reverse_table`. --- Library/Homebrew/tap.rb | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/Library/Homebrew/tap.rb b/Library/Homebrew/tap.rb index 4396e3ea9e..77a489585e 100644 --- a/Library/Homebrew/tap.rb +++ b/Library/Homebrew/tap.rb @@ -150,7 +150,6 @@ class Tap @full_name = "#{@user}/homebrew-#{@repo}" @path = TAP_DIRECTORY/@full_name.downcase @git_repo = GitRepository.new(@path) - @alias_reverse_table = nil end # Clear internal cache. @@ -724,17 +723,15 @@ class Tap end end - # a table mapping formula name to aliases + # Mapping from formula names to aliases. + # # @private + sig { returns(T::Hash[String, T::Array[String]]) } def alias_reverse_table - return @alias_reverse_table if @alias_reverse_table - - @alias_reverse_table = {} - alias_table.each do |alias_name, formula_name| - @alias_reverse_table[formula_name] ||= [] - @alias_reverse_table[formula_name] << alias_name + @alias_reverse_table ||= alias_table.each_with_object({}) do |(alias_name, formula_name), alias_reverse_table| + alias_reverse_table[formula_name] ||= [] + alias_reverse_table[formula_name] << alias_name end - @alias_reverse_table end sig { returns(Pathname) }