* 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
This commit is contained in:
tenderlove 2013-10-29 18:25:57 +00:00
Родитель 64d97719ff
Коммит 06c6dcee25
2 изменённых файлов: 16 добавлений и 7 удалений

Просмотреть файл

@ -1,3 +1,8 @@
Wed Oct 30 03:25:10 2013 Aaron Patterson <aaron@tenderlovemaking.com>
* ext/psych/lib/psych/visitors/yaml_tree.rb: make less garbage when
testing if a string is binary.
Wed Oct 30 03:08:24 2013 Aaron Patterson <aaron@tenderlovemaking.com> Wed Oct 30 03:08:24 2013 Aaron Patterson <aaron@tenderlovemaking.com>
* ext/psych/lib/psych/visitors/yaml_tree.rb: string subclasses should * ext/psych/lib/psych/visitors/yaml_tree.rb: string subclasses should

Просмотреть файл

@ -264,13 +264,6 @@ module Psych
@emitter.scalar o._dump, nil, '!ruby/object:BigDecimal', false, false, Nodes::Scalar::ANY @emitter.scalar o._dump, nil, '!ruby/object:BigDecimal', false, false, Nodes::Scalar::ANY
end 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 def visit_String o
plain = true plain = true
quote = true quote = true
@ -380,6 +373,17 @@ module Psych
end end
private 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 def visit_array_subclass o
tag = "!ruby/array:#{o.class}" tag = "!ruby/array:#{o.class}"
if o.instance_variables.empty? if o.instance_variables.empty?