[前][次][番号順一覧][スレッド一覧]

ruby-changes:31392

From: tenderlove <ko1@a...>
Date: Wed, 30 Oct 2013 03:26:02 +0900 (JST)
Subject: [ruby-changes:31392] tenderlove:r43471 (trunk): * ext/psych/lib/psych/visitors/yaml_tree.rb: make less garbage when

tenderlove	2013-10-30 03:25:57 +0900 (Wed, 30 Oct 2013)

  New Revision: 43471

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=43471

  Log:
    * ext/psych/lib/psych/visitors/yaml_tree.rb: make less garbage when
      testing if a string is binary.

  Modified files:
    trunk/ChangeLog
    trunk/ext/psych/lib/psych/visitors/yaml_tree.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 43470)
+++ ChangeLog	(revision 43471)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Oct 30 03:25:10 2013  Aaron Patterson <aaron@t...>
+
+	* 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@t...>
 
 	* ext/psych/lib/psych/visitors/yaml_tree.rb: string subclasses should
Index: ext/psych/lib/psych/visitors/yaml_tree.rb
===================================================================
--- ext/psych/lib/psych/visitors/yaml_tree.rb	(revision 43470)
+++ ext/psych/lib/psych/visitors/yaml_tree.rb	(revision 43471)
@@ -264,13 +264,6 @@ module Psych https://github.com/ruby/ruby/blob/trunk/ext/psych/lib/psych/visitors/yaml_tree.rb#L264
         @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 https://github.com/ruby/ruby/blob/trunk/ext/psych/lib/psych/visitors/yaml_tree.rb#L373
       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?

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]