summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorwanabe <[email protected]>2025-01-15 12:30:59 +0900
committergit <[email protected]>2025-01-15 04:07:43 +0000
commit272a8c3c3f334876c2246dcf9ce4d4c71fe52a78 (patch)
tree89bfcf6a07ffea08c48e54a46d5280ddefb22d7a /lib
parent96b5cde28bba189b6cfddce5d507eb751dda03b3 (diff)
[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
Diffstat (limited to 'lib')
-rw-r--r--lib/erb/compiler.rb12
1 files 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