Skip to content

Commit 5ff14c3

Browse files
committed
[GR-34943] Use a ConcurrentMap for @@stubs_by_name in Gem::Specification
PullRequest: truffleruby/4055
2 parents 8d9ddfc + 4061462 commit 5ff14c3

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

lib/mri/rubygems/specification.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ class Gem::Specification < Gem::BasicSpecification
181181
def self.clear_specs # :nodoc:
182182
@@all = nil
183183
@@stubs = nil
184-
@@stubs_by_name = {}
184+
@@stubs_by_name = TruffleRuby::ConcurrentMap.new
185185
@@spec_with_requirable_file = {}
186186
@@active_stub_with_requirable_file = {}
187187
end
@@ -818,7 +818,9 @@ def self.stubs
818818
pattern = "*.gemspec"
819819
stubs = stubs_for_pattern(pattern, false)
820820

821-
@@stubs_by_name = stubs.select {|s| Gem::Platform.match_spec? s }.group_by(&:name)
821+
stubs_by_name = TruffleRuby::ConcurrentMap.new
822+
stubs.select {|s| Gem::Platform.match_spec? s }.group_by(&:name).each_pair { |k, v| stubs_by_name[k] = v }
823+
@@stubs_by_name = stubs_by_name
822824
stubs
823825
end
824826
end
@@ -929,7 +931,9 @@ def self.all
929931
# -- wilsonb
930932

931933
def self.all=(specs)
932-
@@stubs_by_name = specs.group_by(&:name)
934+
stubs_by_name = TruffleRuby::ConcurrentMap.new
935+
specs.group_by(&:name).each_pair { |k, v| stubs_by_name[k] = v }
936+
@@stubs_by_name = stubs_by_name
933937
@@all = @@stubs = specs
934938
end
935939

test/mri/tests/rubygems/test_gem_specification.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -996,9 +996,9 @@ def test_self_stubs_for_lazy_loading
996996
save_gemspec("b-1", "1", dir_standard_specs) {|s| s.name = "b" }
997997

998998
assert_equal ["a-1"], Gem::Specification.stubs_for("a").map {|s| s.full_name }
999-
assert_equal 1, Gem::Specification.class_variable_get(:@@stubs_by_name).length
999+
assert_equal 1, Gem::Specification.class_variable_get(:@@stubs_by_name).size
10001000
assert_equal ["b-1"], Gem::Specification.stubs_for("b").map {|s| s.full_name }
1001-
assert_equal 2, Gem::Specification.class_variable_get(:@@stubs_by_name).length
1001+
assert_equal 2, Gem::Specification.class_variable_get(:@@stubs_by_name).size
10021002

10031003
assert_equal(
10041004
Gem::Specification.stubs_for("a").map {|s| s.object_id },

0 commit comments

Comments
 (0)