summaryrefslogtreecommitdiff
path: root/ext/psych
diff options
context:
space:
mode:
authortenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-10-29 18:25:57 +0000
committertenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-10-29 18:25:57 +0000
commit06c6dcee25d983d5a5e0f8e576cd04978ed558e6 (patch)
tree2356d7af52e7c13586bfdd463a51b875f270560d /ext/psych
parent64d97719ffebbc1e792ecf10e5eac1971eb1de40 (diff)
* ext/psych/lib/psych/visitors/yaml_tree.rb: make less garbage when
testing if a string is binary. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43471 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/psych')
-rw-r--r--ext/psych/lib/psych/visitors/yaml_tree.rb18
1 files changed, 11 insertions, 7 deletions
diff --git a/ext/psych/lib/psych/visitors/yaml_tree.rb b/ext/psych/lib/psych/visitors/yaml_tree.rb
index 65cbba0..b469e2d 100644
--- a/ext/psych/lib/psych/visitors/yaml_tree.rb
+++ b/ext/psych/lib/psych/visitors/yaml_tree.rb
@@ -264,13 +264,6 @@ module Psych
@emitter.scalar o._dump, nil, '!ruby/object:BigDecimal', false, false, Nodes::Scalar::ANY
end
- def binary? string
- (string.encoding == Encoding::ASCII_8BIT && !string.ascii_only?) ||
- string.index("\x00") ||
- string.count("\x00-\x7F", "^ -~\t\r\n").fdiv(string.length) > 0.3
- end
- private :binary?
-
def visit_String o
plain = true
quote = true
@@ -380,6 +373,17 @@ module Psych
end
private
+ # FIXME: Remove the index and count checks in Psych 3.0
+ NULL = "\x00"
+ BINARY_RANGE = "\x00-\x7F"
+ WS_RANGE = "^ -~\t\r\n"
+
+ def binary? string
+ (string.encoding == Encoding::ASCII_8BIT && !string.ascii_only?) ||
+ string.index(NULL) ||
+ string.count(BINARY_RANGE, WS_RANGE).fdiv(string.length) > 0.3
+ end
+
def visit_array_subclass o
tag = "!ruby/array:#{o.class}"
if o.instance_variables.empty?