Skip to content

Commit

Permalink
[ruby/erb] Make @scanner_map of ERB::Compiler::Scanner ractor-sha…
Browse files Browse the repository at this point in the history
…reable

- Freeze on assignment
- Recreate Hash on registration

ruby/erb@12d69fc2b3
  • Loading branch information
wanabe authored and matzbot committed Jan 15, 2025
1 parent 96b5cde commit 272a8c3
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/erb/compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,16 @@ def initialize(str)
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
Expand Down

0 comments on commit 272a8c3

Please sign in to comment.