Fuse the rpath loops.

We previously looped twice over the `rpath`s, but we actually only need
to do that once.
This commit is contained in:
Carlo Cabrera 2022-01-18 19:29:58 +08:00
parent 57fae524de
commit ffb3c9cff9
No known key found for this signature in database
GPG Key ID: C74D447FC549A1D0

View File

@ -54,21 +54,20 @@ class Keg
change_install_name(bad_name, new_name, file) unless new_name == bad_name
end
# Count duplicate rpaths. We need to keep track of this ourselves
# because the MachO data is cached and this cache is not updated
# after modification with #delete_rpath.
rpath_dupe_count = Hash.new { |h, k| h[k] = -1 }
file.rpaths.each do |rpath|
rpath_dupe_count[rpath] += 1
end
# Keep track of the rpath counts for deletion of duplicates.
# We need to track this here since we cache the MachO data [0]
# and this cache is not updated after modification with #delete_rpath.
#
# [0] See os/mac/mach.rb.
rpath_count = Hash.new { |h, k| h[k] = file.rpaths.count(k) }
each_linkage_for(file, :rpaths) do |bad_name|
# Strip duplicate rpaths and rpaths rooted in the build directory
# Strip duplicate rpaths and rpaths rooted in the build directory.
next if !bad_name.start_with?(HOMEBREW_TEMP.to_s) &&
!bad_name.start_with?(HOMEBREW_TEMP.realpath.to_s) &&
(rpath_dupe_count[bad_name] <= 0)
(rpath_count[bad_name] == 1)
rpath_dupe_count[bad_name] -= 1
rpath_count[bad_name] -= 1
delete_rpath(bad_name, file)
end
end