formula: try optimise versioned_formulae_names

This commit is contained in:
Bo Anderson 2022-08-25 15:05:49 +01:00
parent 677bb92ba9
commit f09be9a5f7
No known key found for this signature in database
GPG Key ID: 3DB94E204E137D65

View File

@ -447,7 +447,17 @@ class Formula
# Returns any `@`-versioned formulae names for any formula (including versioned formulae).
sig { returns(T::Array[String]) }
def versioned_formulae_names
Pathname.glob(path.to_s.gsub(/(@[\d.]+)?\.rb$/, "@*.rb")).map do |versioned_path|
versioned_paths = if tap
# Faster path, due to `tap.versioned_formula_files` caching.
name_prefix = "#{name.gsub(/(@[\d.]+)?$/, "")}@"
tap.versioned_formula_files.select do |file|
file.basename.to_s.start_with?(name_prefix)
end
else
Pathname.glob(path.to_s.gsub(/(@[\d.]+)?\.rb$/, "@*.rb"))
end
versioned_paths.map do |versioned_path|
next if versioned_path == path
versioned_path.basename(".rb").to_s