[rubygems/rubygems] Avoid re-compiling static regexp in a loop

Pathname::SEPARATOR_PAT is a constant and can safely be interpolated once, avoiding creating a new regexp object on every iteration

https://github.com/rubygems/rubygems/commit/75d9c0f1e4
This commit is contained in:
Samuel Giddins 2023-11-27 16:01:51 -06:00 committed by git
parent 8234763816
commit 2927c28095

View File

@ -226,7 +226,7 @@ module Bundler
# Some gem authors put absolute paths in their gemspec
# and we have to save them from themselves
spec.files = spec.files.map do |path|
next path unless /\A#{Pathname::SEPARATOR_PAT}/.match?(path)
next path unless /\A#{Pathname::SEPARATOR_PAT}/o.match?(path)
next if File.directory?(path)
begin
Pathname.new(path).relative_path_from(gem_dir).to_s