Skip to content

Commit 4b0c1b2

Browse files
committed
Use new TruffleRuby::ConcurrentMap backend for Concurrent::Map
1 parent 7b7900a commit 4b0c1b2

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module Concurrent
2+
3+
# @!visibility private
4+
module Collection
5+
6+
# @!visibility private
7+
class TruffleRubyMapBackend < TruffleRuby::ConcurrentMap
8+
def initialize(options = nil)
9+
options ||= {}
10+
super(initial_capacity: options[:initial_capacity], load_factor: options[:load_factor])
11+
end
12+
end
13+
end
14+
end

lib/concurrent-ruby/concurrent/map.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,13 @@ module Collection
1616
require 'concurrent/collection/map/mri_map_backend'
1717
MriMapBackend
1818
when Concurrent.on_rbx? || Concurrent.on_truffleruby?
19-
require 'concurrent/collection/map/atomic_reference_map_backend'
20-
AtomicReferenceMapBackend
19+
if defined?(::TruffleRuby::ConcurrentMap)
20+
require 'concurrent/collection/map/truffleruby_map_backend'
21+
TruffleRubyMapBackend
22+
else
23+
require 'concurrent/collection/map/atomic_reference_map_backend'
24+
AtomicReferenceMapBackend
25+
end
2126
else
2227
warn 'Concurrent::Map: unsupported Ruby engine, using a fully synchronized Concurrent::Map implementation'
2328
require 'concurrent/collection/map/synchronized_map_backend'

0 commit comments

Comments
 (0)