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

ruby-changes:36228

From: nobu <ko1@a...>
Date: Fri, 7 Nov 2014 00:00:29 +0900 (JST)
Subject: [ruby-changes:36228] nobu:r48309 (trunk): normalize.rb: trivial optimizations

nobu	2014-11-07 00:00:17 +0900 (Fri, 07 Nov 2014)

  New Revision: 48309

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

  Log:
    normalize.rb: trivial optimizations
    
    * lib/unicode_normalize/normalize.rb (nfc_one, normalize): trivial
      optimizations.

  Modified files:
    trunk/lib/unicode_normalize/normalize.rb
Index: lib/unicode_normalize/normalize.rb
===================================================================
--- lib/unicode_normalize/normalize.rb	(revision 48308)
+++ lib/unicode_normalize/normalize.rb	(revision 48309)
@@ -106,7 +106,7 @@ module UnicodeNormalize https://github.com/ruby/ruby/blob/trunk/lib/unicode_normalize/normalize.rb#L106
     string
   end
 
-  def self.nfc_one (string)
+  def self.nfc_one(string)
     nfd_string = nfd_one string
     start = nfd_string[0]
     last_class = CLASS_TABLE[start]-1
@@ -116,7 +116,7 @@ module UnicodeNormalize https://github.com/ruby/ruby/blob/trunk/lib/unicode_normalize/normalize.rb#L116
       if last_class<accent_class and composite = COMPOSITION_TABLE[start+accent]
         start = composite
       else
-        accents += accent
+        accents << accent
         last_class = accent_class
       end
     end
@@ -125,7 +125,8 @@ module UnicodeNormalize https://github.com/ruby/ruby/blob/trunk/lib/unicode_normalize/normalize.rb#L125
 
   def self.normalize(string, form = :nfc)
     encoding = string.encoding
-    if encoding == Encoding::UTF_8
+    case encoding
+    when Encoding::UTF_8
       case form
       when :nfc then
         string.gsub REGEXP_C, NF_HASH_C
@@ -138,9 +139,9 @@ module UnicodeNormalize https://github.com/ruby/ruby/blob/trunk/lib/unicode_normalize/normalize.rb#L139
       else
         raise ArgumentError, "Invalid normalization form #{form}."
       end
-    elsif encoding == Encoding::US_ASCII
+    when Encoding::US_ASCII
       string
-    elsif  UNICODE_ENCODINGS.include? encoding
+    when *UNICODE_ENCODINGS
       normalize(string.encode(Encoding::UTF_8), form).encode(encoding)
     else
       raise Encoding::CompatibilityError, "Unicode Normalization not appropriate for #{encoding}"

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

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