Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

* ext/psych/lib/psych/visitors/yaml_tree.rb: make less garbage when

  testing if a string is binary.
  • Loading branch information...
commit 41152b94465765e77bf5c479e3d542339b61459f 1 parent 2ffd057
@tenderlove authored
Showing with 16 additions and 7 deletions.
  1. +5 −0 CHANGELOG.rdoc
  2. +11 −7 lib/psych/visitors/yaml_tree.rb
View
5 CHANGELOG.rdoc
@@ -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>
* ext/psych/lib/psych/visitors/yaml_tree.rb: string subclasses should
View
18 lib/psych/visitors/yaml_tree.rb
@@ -264,13 +264,6 @@ def visit_BigDecimal o
@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 @@ def visit_Symbol o
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?
Please sign in to comment.
Something went wrong with that request. Please try again.