From 272a8c3c3f334876c2246dcf9ce4d4c71fe52a78 Mon Sep 17 00:00:00 2001 From: wanabe Date: Wed, 15 Jan 2025 12:30:59 +0900 Subject: [PATCH] [ruby/erb] Make `@scanner_map` of `ERB::Compiler::Scanner` ractor-shareable - Freeze on assignment - Recreate Hash on registration https://github.com/ruby/erb/commit/12d69fc2b3 --- lib/erb/compiler.rb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/erb/compiler.rb b/lib/erb/compiler.rb index 7096c8dcea..74947a9a5f 100644 --- a/lib/erb/compiler.rb +++ b/lib/erb/compiler.rb @@ -80,10 +80,16 @@ class ERB::Compiler # :nodoc: end class Scanner # :nodoc: - @scanner_map = {} + @scanner_map = defined?(Ractor) ? Ractor.make_shareable({}) : {} class << self - def register_scanner(klass, trim_mode, percent) - @scanner_map[[trim_mode, percent]] = klass + if defined?(Ractor) + def register_scanner(klass, trim_mode, percent) + @scanner_map = Ractor.make_shareable({ **@scanner_map, [trim_mode, percent] => klass }) + end + else + def register_scanner(klass, trim_mode, percent) + @scanner_map[[trim_mode, percent]] = klass + end end alias :regist_scanner :register_scanner end