Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid repeated access to Ractor.current #474

Merged
merged 2 commits into from
Jan 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions lib/psych/visitors/to_ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def initialize ss, class_loader, symbolize_names: false, freeze: false
super()
@st = {}
@ss = ss
@load_tags = Psych.load_tags
@domain_types = Psych.domain_types
@class_loader = class_loader
@symbolize_names = symbolize_names
Expand All @@ -48,7 +49,7 @@ def accept target
end

def deserialize o
if klass = resolve_class(Psych.load_tags[o.tag])
if klass = resolve_class(@load_tags[o.tag])
instance = klass.allocate

if instance.respond_to?(:init_with)
Expand Down Expand Up @@ -128,7 +129,7 @@ def visit_Psych_Nodes_Scalar o
end

def visit_Psych_Nodes_Sequence o
if klass = resolve_class(Psych.load_tags[o.tag])
if klass = resolve_class(@load_tags[o.tag])
instance = klass.allocate

if instance.respond_to?(:init_with)
Expand Down Expand Up @@ -160,8 +161,8 @@ def visit_Psych_Nodes_Sequence o
end

def visit_Psych_Nodes_Mapping o
if Psych.load_tags[o.tag]
return revive(resolve_class(Psych.load_tags[o.tag]), o)
if @load_tags[o.tag]
return revive(resolve_class(@load_tags[o.tag]), o)
end
return revive_hash(register(o, {}), o) unless o.tag

Expand Down Expand Up @@ -326,6 +327,7 @@ def visit_Psych_Nodes_Alias o
end

private

def register node, object
@st[node.anchor] = object if node.anchor
object
Expand Down
2 changes: 1 addition & 1 deletion lib/psych/visitors/visitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def self.dispatch_cache

if defined?(Ractor)
def dispatch
Ractor.current[:Psych_Visitors_Visitor] ||= Visitor.dispatch_cache
@dispatch_cache ||= (Ractor.current[:Psych_Visitors_Visitor] ||= Visitor.dispatch_cache)
end
else
DISPATCH = dispatch_cache
Expand Down