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

ruby-changes:37848

From: nobu <ko1@a...>
Date: Wed, 11 Mar 2015 12:56:54 +0900 (JST)
Subject: [ruby-changes:37848] nobu:r49929 (trunk): normalize.rb: remove redundant hash

nobu	2015-03-11 12:56:44 +0900 (Wed, 11 Mar 2015)

  New Revision: 49929

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

  Log:
    normalize.rb: remove redundant hash
    
    * lib/unicode_normalize/normalize.rb (UnicodeNormalize): REGEXP_K
      matches only single chars which are keys of KOMPATIBLE_TABLE, so
      string in nfkd_one is always single char and one of the key of
      KOMPATIBLE_TABLE, that is that the default proc of NF_HASH_K only
      copies a pair in KOMPATIBLE_TABLE.  therefore NF_HASH_K is a
      part of KOMPATIBLE_TABLE always, and just redundant.

  Modified files:
    trunk/lib/unicode_normalize/normalize.rb
Index: lib/unicode_normalize/normalize.rb
===================================================================
--- lib/unicode_normalize/normalize.rb	(revision 49928)
+++ lib/unicode_normalize/normalize.rb	(revision 49929)
@@ -21,10 +21,6 @@ module UnicodeNormalize https://github.com/ruby/ruby/blob/trunk/lib/unicode_normalize/normalize.rb#L21
                          hash.shift if hash.length>MAX_HASH_LENGTH # prevent DoS attack
                          hash[key] = nfc_one(key)
                        end
-  NF_HASH_K = Hash.new do |hash, key|
-                         hash.shift if hash.length>MAX_HASH_LENGTH # prevent DoS attack
-                         hash[key] = nfkd_one(key)
-                       end
 
   ## Constants For Hangul
   # for details such as the meaning of the identifiers below, please see
@@ -88,10 +84,6 @@ module UnicodeNormalize https://github.com/ruby/ruby/blob/trunk/lib/unicode_normalize/normalize.rb#L84
     canonical_ordering_one(hangul_decomp_one(string))
   end
 
-  def self.nfkd_one(string)
-    string.chars.map! {|c| KOMPATIBLE_TABLE[c] || c}.join('')
-  end
-
   def self.nfc_one(string)
     nfd_string = nfd_one string
     start = nfd_string[0]
@@ -119,9 +111,9 @@ module UnicodeNormalize https://github.com/ruby/ruby/blob/trunk/lib/unicode_normalize/normalize.rb#L111
       when :nfd then
         string.gsub REGEXP_D, NF_HASH_D
       when :nfkc then
-        string.gsub(REGEXP_K, NF_HASH_K).gsub REGEXP_C, NF_HASH_C
+        string.gsub(REGEXP_K, KOMPATIBLE_TABLE).gsub(REGEXP_C, NF_HASH_C)
       when :nfkd then
-        string.gsub(REGEXP_K, NF_HASH_K).gsub REGEXP_D, NF_HASH_D
+        string.gsub(REGEXP_K, KOMPATIBLE_TABLE).gsub(REGEXP_D, NF_HASH_D)
       else
         raise ArgumentError, "Invalid normalization form #{form}."
       end

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

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