Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Handle nil tags specially to avoid slow method_missing calls.

Previously, the nil value would be compared to any RegExps, which causes method_missing to be invoked on nil, which is both slow and always guaranteed to fail matching against the RegExp.
  • Loading branch information...
commit 85a1ae2fac470fddc2c06b0f6d55ba94677356a5 1 parent 08da2c2
@nirvdrum nirvdrum authored
Showing with 9 additions and 3 deletions.
  1. +9 −3 lib/psych/visitors/to_ruby.rb
View
12 lib/psych/visitors/to_ruby.rb
@@ -118,6 +118,8 @@ def visit_Psych_Nodes_Sequence o
end
case o.tag
+ when nil
+ register_empty(o)
when '!omap', 'tag:yaml.org,2002:omap'
map = register(o, Psych::Omap.new)
o.children.each { |a|
@@ -130,9 +132,7 @@ def visit_Psych_Nodes_Sequence o
o.children.each { |c| list.push accept c }
list
else
- list = register(o, [])
- o.children.each { |c| list.push accept c }
- list
+ register_empty(o)
end
end
@@ -252,6 +252,12 @@ def register node, object
object
end
+ def register_empty object
+ list = register(object, [])
+ object.children.each { |c| list.push accept c }
+ list
+ end
+
def revive_hash hash, o
@st[o.anchor] = hash if o.anchor
Please sign in to comment.
Something went wrong with that request. Please try again.