summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Jirutka <jakub@jirutka.cz>2015-01-12 20:51:03 +0100
committerJakub Jirutka <jakub@jirutka.cz>2015-01-12 20:51:03 +0100
commit9a811d65852fa3fd556c475652c321263d148edd (patch)
tree1ba505e637178fd3ba89c7142f5ee88045439e5d
parent2edf642b82ae88ed93ec5f6ed7ae699771c04fc6 (diff)
downloadpsych-9a811d65852fa3fd556c475652c321263d148edd.tar.gz
Preset @line_width in YAMLTree#initialize for better performance
-rw-r--r--lib/psych/visitors/yaml_tree.rb21
1 files changed, 9 insertions, 12 deletions
diff --git a/lib/psych/visitors/yaml_tree.rb b/lib/psych/visitors/yaml_tree.rb
index 976ea8d..ba1ac13 100644
--- a/lib/psych/visitors/yaml_tree.rb
+++ b/lib/psych/visitors/yaml_tree.rb
@@ -62,13 +62,14 @@ module Psych
def initialize emitter, ss, options
super()
- @started = false
- @finished = false
- @emitter = emitter
- @st = Registrar.new
- @ss = ss
- @options = options
- @coders = []
+ @started = false
+ @finished = false
+ @emitter = emitter
+ @st = Registrar.new
+ @ss = ss
+ @options = options
+ @line_width = options[:line_width]
+ @coders = []
@dispatch_cache = Hash.new do |h,klass|
method = "visit_#{(klass.name || '').split('::').join('_')}"
@@ -316,7 +317,7 @@ module Psych
tag = 'tag:yaml.org,2002:str'
plain = false
quote = false
- elsif line_width != 0 && o.length > line_width
+ elsif @line_width && o.length > @line_width
style = Nodes::Scalar::FOLDED
o += "\n" unless o =~ /\n\Z/ # to avoid non-default chomping indicator
elsif o =~ /^[^[:word:]][^"]*$/
@@ -589,10 +590,6 @@ module Psych
accept target.instance_variable_get(iv)
end
end
-
- def line_width
- @line_width ||= (@options[:line_width] || 0)
- end
end
end
end