Avoid repeated calls to affix checks

This commit is contained in:
Douglas Eichelberger 2025-08-31 11:11:41 -07:00
parent 9219495eb0
commit 240fd71e6f
No known key found for this signature in database
GPG Key ID: F90193CBD547EB81
5 changed files with 5 additions and 5 deletions

View File

@ -384,7 +384,7 @@ module Homebrew
files_to_commits[file] ||= []
files_to_commits[file] << commit
tap_file = (tap.path/file).to_s
if (tap_file.start_with?("#{tap.formula_dir}/") || tap_file.start_with?("#{tap.cask_dir}/")) &&
if tap_file.start_with?("#{tap.formula_dir}/", "#{tap.cask_dir}/") &&
File.extname(file) == ".rb"
next
end

View File

@ -376,7 +376,7 @@ module OS
return if @found.all? do |path|
realpath = Pathname.new(path).realpath.to_s
allowlist.any? { |rack| realpath.start_with?(rack) }
realpath.start_with?(*allowlist)
end
end

View File

@ -272,7 +272,7 @@ module OS
# https://gitlab.kitware.com/cmake/cmake/-/issues/23251
return true if HOMEBREW_TEMP.to_s == "/private/tmp" && filename.start_with?("/tmp/")
filename.start_with?(HOMEBREW_TEMP.to_s) || filename.start_with?(HOMEBREW_TEMP.realpath.to_s)
filename.start_with?(HOMEBREW_TEMP.to_s, HOMEBREW_TEMP.realpath.to_s)
end
end
end

View File

@ -281,7 +281,7 @@ class Cmd
true
# first two paths: reject references to Cellar or opt paths
# for unspecified dependencies
elsif path.start_with?(cellar) || path.start_with?(opt)
elsif path.start_with?(cellar, opt)
dep = path[keg_regex, 2]
dep && @deps.include?(dep)
elsif path.start_with?(prefix, cachedir, tmpdir)

View File

@ -92,7 +92,7 @@ module UnpackStrategy
strategies&.sort_by { |s| s.extensions.map(&:length).max || 0 }
&.reverse
&.find { |s| s.extensions.any? { |ext| extension.end_with?(ext) } }
&.find { |s| extension.end_with?(*s.extensions) }
end
sig { params(path: Pathname).returns(T.nilable(UnpackStrategyType)) }