Skip to content

Commit 12d69fc

Browse files
wanabek0kubun
authored andcommitted
Make @scanner_map of ERB::Compiler::Scanner ractor-shareable
- Freeze on assignment - Recreate Hash on registration
1 parent 348777b commit 12d69fc

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

lib/erb/compiler.rb

+9-3
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,16 @@ def initialize(str)
8080
end
8181

8282
class Scanner # :nodoc:
83-
@scanner_map = {}
83+
@scanner_map = defined?(Ractor) ? Ractor.make_shareable({}) : {}
8484
class << self
85-
def register_scanner(klass, trim_mode, percent)
86-
@scanner_map[[trim_mode, percent]] = klass
85+
if defined?(Ractor)
86+
def register_scanner(klass, trim_mode, percent)
87+
@scanner_map = Ractor.make_shareable({ **@scanner_map, [trim_mode, percent] => klass })
88+
end
89+
else
90+
def register_scanner(klass, trim_mode, percent)
91+
@scanner_map[[trim_mode, percent]] = klass
92+
end
8793
end
8894
alias :regist_scanner :register_scanner
8995
end

0 commit comments

Comments
 (0)