Permalink
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...
1 parent 08da2c2 commit 85a1ae2fac470fddc2c06b0f6d55ba94677356a5 @nirvdrum nirvdrum committed Oct 1, 2012
Showing with 9 additions and 3 deletions.
  1. +9 −3 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

0 comments on commit 85a1ae2

Please sign in to comment.