From 3854df000780465f6e78b084732d5ab324be941e Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 14 Oct 2009 14:48:33 -0700 Subject: speeding some stuff up --- lib/psych/nodes/scalar.rb | 1 - lib/psych/tree_builder.rb | 31 ++++++++++++++++++++++--------- 2 files changed, 22 insertions(+), 10 deletions(-) (limited to 'lib') diff --git a/lib/psych/nodes/scalar.rb b/lib/psych/nodes/scalar.rb index fac4d69..3bf2a2e 100644 --- a/lib/psych/nodes/scalar.rb +++ b/lib/psych/nodes/scalar.rb @@ -30,7 +30,6 @@ module Psych attr_accessor :style def initialize value, anchor = nil, tag = nil, plain = true, quoted = false, style = ANY - super() @value = value @anchor = anchor @tag = tag diff --git a/lib/psych/tree_builder.rb b/lib/psych/tree_builder.rb index 089ee96..075163e 100644 --- a/lib/psych/tree_builder.rb +++ b/lib/psych/tree_builder.rb @@ -10,6 +10,7 @@ module Psych class TreeBuilder < Psych::Handler def initialize @stack = [] + @last = nil end def root @@ -23,36 +24,48 @@ module Psych class_eval %{ def start_#{node.downcase}(*args) n = Nodes::#{node}.new(*args) - @stack.last.children << n - @stack.push n + @last.children << n + push n end def end_#{node.downcase} - @stack.pop + pop end } end def start_document(*args) n = Nodes::Document.new(*args) - @stack.last.children << n - @stack.push n + @last.children << n + push n end def end_document implicit_end - @stack.pop.implicit_end = implicit_end + @last.implicit_end = implicit_end + pop end def start_stream encoding - @stack.push Nodes::Stream.new(encoding) + push Nodes::Stream.new(encoding) end def scalar(*args) - @stack.last.children << Nodes::Scalar.new(*args) + @last.children << Nodes::Scalar.new(*args) end def alias(*args) - @stack.last.children << Nodes::Alias.new(*args) + @last.children << Nodes::Alias.new(*args) + end + + private + def push value + @stack.push value + @last = value + end + + def pop + @stack.pop + @last = @stack.last end end end -- cgit v1.2.3