1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[rubygems/rubygems] Fix performance regression in require

Our check for `-I` paths should not go through all activated gems.

https://github.com/rubygems/rubygems/commit/00d98eb8a3
This commit is contained in:
David Rodríguez 2020-05-19 14:00:00 +02:00 committed by Hiroshi SHIBATA
parent 8c8364c84e
commit a18e81d797
Notes: git 2020-06-05 07:33:42 +09:00
4 changed files with 23 additions and 1 deletions

View file

@ -593,10 +593,20 @@ An Array (#{env.inspect}) was passed in from #{caller[3]}
index
end
##
# The number of paths in the `$LOAD_PATH` from activated gems. Used to
# prioritize `-I` and `ENV['RUBYLIB`]` entries during `require`.
def self.activated_gem_paths
@activated_gem_paths ||= 0
end
##
# Add a list of paths to the $LOAD_PATH at the proper place.
def self.add_to_load_path(*paths)
@activated_gem_paths = activated_gem_paths + paths.size
insert_index = load_path_insert_index
if insert_index

View file

@ -47,7 +47,7 @@ module Kernel
load_path_insert_index = Gem.load_path_insert_index
break unless load_path_insert_index
$LOAD_PATH[0...load_path_insert_index].each do |lp|
$LOAD_PATH[0...load_path_insert_index - Gem.activated_gem_paths].each do |lp|
safe_lp = lp.dup.tap(&Gem::UNTAINT)
begin
if File.symlink? safe_lp # for backward compatibility

View file

@ -388,6 +388,7 @@ class Gem::TestCase < Minitest::Test
Gem::Security.reset
Gem.loaded_specs.clear
Gem.instance_variable_set(:@activated_gem_paths, 0)
Gem.clear_default_specs
Bundler.reset!

View file

@ -382,6 +382,17 @@ class TestGemRequire < Gem::TestCase
assert_equal 0, times_called
end
def test_second_gem_require_does_not_resolve_path_manually_before_going_through_standard_require
a1 = util_spec "a", "1", nil, "lib/test_gem_require_a.rb"
install_gem a1
assert_require "test_gem_require_a"
stub(:gem_original_require, ->(path) { assert_equal "test_gem_require_a", path }) do
require "test_gem_require_a"
end
end
def test_realworld_default_gem
testing_ruby_repo = !ENV["GEM_COMMAND"].nil?
skip "this test can't work under ruby-core setup" if testing_ruby_repo || java_platform?