Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve performance of Formula#to_hash #16052

Merged
merged 1 commit into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 3 additions & 4 deletions Library/Homebrew/formula.rb
Original file line number Diff line number Diff line change
Expand Up @@ -537,8 +537,7 @@ def oldname
sig { returns(T::Array[String]) }
def oldnames
@oldnames ||= if tap
T.must(tap).formula_renames
.flat_map { |old_name, new_name| (new_name == name) ? old_name : [] }
T.must(tap).formula_oldnames.fetch(name, [])
else
[]
end
Expand Down Expand Up @@ -2237,7 +2236,7 @@ def to_hash
"versions" => {
"stable" => stable&.version&.to_s,
"head" => head&.version&.to_s,
"bottle" => !bottle_specification.checksums.empty?,
"bottle" => bottle_defined?,
},
"urls" => {},
"revision" => revision,
Expand Down Expand Up @@ -2434,7 +2433,7 @@ def bottle_hash
"files" => {},
}
bottle_spec.collector.each_tag do |tag|
tag_spec = bottle_spec.collector.specification_for(tag)
tag_spec = bottle_spec.collector.specification_for(tag, no_older_versions: true)
os_cellar = tag_spec.cellar
os_cellar = os_cellar.inspect if os_cellar.is_a?(Symbol)

Expand Down
9 changes: 9 additions & 0 deletions Library/Homebrew/tap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,15 @@
end
end

# Hash with tap formula old names. Reverse of {#formula_renames}.
sig { returns(T::Hash[String, T::Array[String]]) }
def formula_oldnames
@formula_oldnames ||= formula_renames.each_with_object({}) do |(old_name, new_name), hash|
hash[new_name] ||= []
hash[new_name] << old_name

Check warning on line 775 in Library/Homebrew/tap.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/tap.rb#L774-L775

Added lines #L774 - L775 were not covered by tests
end
end

# Hash with tap migrations.
sig { returns(Hash) }
def tap_migrations
Expand Down
5 changes: 1 addition & 4 deletions Library/Homebrew/utils/bottles.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,7 @@ def linux?

sig { returns(T::Boolean) }
def macos?
to_macos_version
true
rescue MacOSVersion::Error
false
MacOSVersion::SYMBOLS.key?(system)
end

sig { returns(T::Boolean) }
Expand Down