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

ruby-changes:34187

From: nobu <ko1@a...>
Date: Sat, 31 May 2014 08:56:07 +0900 (JST)
Subject: [ruby-changes:34187] nobu:r46268 (trunk): case-folding.rb: merge tables

nobu	2014-05-31 08:56:00 +0900 (Sat, 31 May 2014)

  New Revision: 46268

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

  Log:
    case-folding.rb: merge tables
    
    * enc/unicode/case-folding.rb (print_table): merge non-locale and
      locale tables, and reduce initializing loops.

  Modified files:
    trunk/ChangeLog
    trunk/enc/unicode/case-folding.rb
    trunk/enc/unicode/casefold.h
    trunk/enc/unicode.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 46267)
+++ ChangeLog	(revision 46268)
@@ -1,4 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
-Sat May 31 08:54:58 2014  Nobuyoshi Nakada  <nobu@r...>
+Sat May 31 08:55:58 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* enc/unicode/case-folding.rb (print_table): merge non-locale and
+	  locale tables, and reduce initializing loops.
 
 	* enc/unicode/case-folding.rb (CaseFolding): modularize, and add
 	  --output-file option.
Index: enc/unicode/casefold.h
===================================================================
--- enc/unicode/casefold.h	(revision 46267)
+++ enc/unicode/casefold.h	(revision 46268)
@@ -1,7 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/enc/unicode/casefold.h#L1
 /* DO NOT EDIT THIS FILE. */
 /* Generated by enc/unicode/case-folding.rb */
 
-static const CaseFold_11_Type CaseFold[] = {
+static const CaseFold_11_Type CaseFold_11_Table[] = {
+#define CaseFold (*(CaseFold_11_Type (*)[1129])(CaseFold_11_Table+0))
   {0x0041, {1, {0x0061}}},
   {0x0042, {1, {0x0062}}},
   {0x0043, {1, {0x0063}}},
@@ -1131,14 +1132,13 @@ static const CaseFold_11_Type CaseFold[] https://github.com/ruby/ruby/blob/trunk/enc/unicode/casefold.h#L1132
   {0x10425, {1, {0x1044d}}},
   {0x10426, {1, {0x1044e}}},
   {0x10427, {1, {0x1044f}}},
-};
-
-static const CaseFold_11_Type CaseFold_Locale[] = {
+#define CaseFold_Locale (*(CaseFold_11_Type (*)[2])(CaseFold_11_Table+1129))
   {0x0049, {1, {0x0069}}},
   {0x0130, {2, {0x0069, 0x0307}}},
 };
 
-static const CaseUnfold_11_Type CaseUnfold_11[] = {
+static const CaseUnfold_11_Type CaseUnfold_11_Table[] = {
+#define CaseUnfold_11 (*(CaseUnfold_11_Type (*)[1005])(CaseUnfold_11_Table+0))
   {0x0061, {1, {0x0041}}},
   {0x0062, {1, {0x0042}}},
   {0x0063, {1, {0x0043}}},
@@ -2144,13 +2144,12 @@ static const CaseUnfold_11_Type CaseUnfo https://github.com/ruby/ruby/blob/trunk/enc/unicode/casefold.h#L2144
   {0x1044d, {1, {0x10425}}},
   {0x1044e, {1, {0x10426}}},
   {0x1044f, {1, {0x10427}}},
-};
-
-static const CaseUnfold_11_Type CaseUnfold_11_Locale[] = {
+#define CaseUnfold_11_Locale (*(CaseUnfold_11_Type (*)[1])(CaseUnfold_11_Table+1005))
   {0x0069, {1, {0x0049}}},
 };
 
-static const CaseUnfold_12_Type CaseUnfold_12[] = {
+static const CaseUnfold_12_Type CaseUnfold_12_Table[] = {
+#define CaseUnfold_12 (*(CaseUnfold_12_Type (*)[58])(CaseUnfold_12_Table+0))
   {{0x0061, 0x02be}, {1, {0x1e9a}}},
   {{0x0066, 0x0066}, {1, {0xfb00}}},
   {{0x0066, 0x0069}, {1, {0xfb01}}},
@@ -2209,13 +2208,12 @@ static const CaseUnfold_12_Type CaseUnfo https://github.com/ruby/ruby/blob/trunk/enc/unicode/casefold.h#L2208
   {{0x1f70, 0x03b9}, {1, {0x1fb2}}},
   {{0x1f74, 0x03b9}, {1, {0x1fc2}}},
   {{0x1f7c, 0x03b9}, {1, {0x1ff2}}},
-};
-
-static const CaseUnfold_12_Type CaseUnfold_12_Locale[] = {
+#define CaseUnfold_12_Locale (*(CaseUnfold_12_Type (*)[1])(CaseUnfold_12_Table+58))
   {{0x0069, 0x0307}, {1, {0x0130}}},
 };
 
-static const CaseUnfold_13_Type CaseUnfold_13[] = {
+static const CaseUnfold_13_Type CaseUnfold_13_Table[] = {
+#define CaseUnfold_13 (*(CaseUnfold_13_Type (*)[14])(CaseUnfold_13_Table+0))
   {{0x0066, 0x0066, 0x0069}, {1, {0xfb03}}},
   {{0x0066, 0x0066, 0x006c}, {1, {0xfb04}}},
   {{0x03b1, 0x0342, 0x03b9}, {1, {0x1fb7}}},
Index: enc/unicode/case-folding.rb
===================================================================
--- enc/unicode/case-folding.rb	(revision 46267)
+++ enc/unicode/case-folding.rb	(revision 46268)
@@ -20,11 +20,14 @@ class CaseFolding https://github.com/ruby/ruby/blob/trunk/enc/unicode/case-folding.rb#L20
     end
 
     def print_table(dest, type, data)
+      dest.print("static const #{type}_Type #{type}_Table[] = {\n")
+      i = 0
       data.each do |n, d|
-        dest.print("static const #{type}_Type #{n}[] = {\n")
+        dest.print("#define #{n} (*(#{type}_Type (*)[#{d.size}])(#{type}_Table+#{i}))\n")
+        i += d.size
         print_table_1(dest, d)
-        dest.print("};\n\n")
       end
+      dest.print("};\n\n")
     end
   end
 
@@ -82,20 +85,17 @@ class CaseFolding https://github.com/ruby/ruby/blob/trunk/enc/unicode/case-folding.rb#L85
 
     # CaseFold + CaseFold_Locale
     name = "CaseFold_11"
-    print_table(dest, name, "CaseFold"=>fold)
-    print_table(dest, name, "CaseFold_Locale"=>fold_locale)
+    print_table(dest, name, "CaseFold"=>fold, "CaseFold_Locale"=>fold_locale)
 
     # print unfolding data
 
     # CaseUnfold_11 + CaseUnfold_11_Locale
     name = "CaseUnfold_11"
-    print_table(dest, name, name=>unfold[0])
-    print_table(dest, name, "#{name}_Locale"=>unfold_locale[0])
+    print_table(dest, name, name=>unfold[0], "#{name}_Locale"=>unfold_locale[0])
 
     # CaseUnfold_12 + CaseUnfold_12_Locale
     name = "CaseUnfold_12"
-    print_table(dest, name, name=>unfold[1])
-    print_table(dest, name, "#{name}_Locale"=>unfold_locale[1])
+    print_table(dest, name, name=>unfold[1], "#{name}_Locale"=>unfold_locale[1])
 
     # CaseUnfold_13
     name = "CaseUnfold_13"
Index: enc/unicode.c
===================================================================
--- enc/unicode.c	(revision 46267)
+++ enc/unicode.c	(revision 46268)
@@ -236,46 +236,30 @@ static int CaseFoldInited = 0; https://github.com/ruby/ruby/blob/trunk/enc/unicode.c#L236
 
 static int init_case_fold_table(void)
 {
-  const CaseFold_11_Type   *p;
-  const CaseUnfold_11_Type *p1;
-  const CaseUnfold_12_Type *p2;
-  const CaseUnfold_13_Type *p3;
   int i;
 
   THREAD_ATOMIC_START;
 
   FoldTable = st_init_numtable_with_size(FOLD_TABLE_SIZE);
   if (ONIG_IS_NULL(FoldTable)) return ONIGERR_MEMORY;
-  for (i = 0; i < numberof(CaseFold); i++) {
-    p = &CaseFold[i];
-    st_add_direct(FoldTable, (st_data_t )p->from, (st_data_t )&(p->to));
-  }
-  for (i = 0; i < numberof(CaseFold_Locale); i++) {
-    p = &CaseFold_Locale[i];
+  for (i = 0; i < numberof(CaseFold_11_Table); i++) {
+    const CaseFold_11_Type *p = &CaseFold_11_Table[i];
     st_add_direct(FoldTable, (st_data_t )p->from, (st_data_t )&(p->to));
   }
 
   Unfold1Table = st_init_numtable_with_size(UNFOLD1_TABLE_SIZE);
   if (ONIG_IS_NULL(Unfold1Table)) return ONIGERR_MEMORY;
 
-  for (i = 0; i < numberof(CaseUnfold_11); i++) {
-    p1 = &CaseUnfold_11[i];
-    st_add_direct(Unfold1Table, (st_data_t )p1->from, (st_data_t )&(p1->to));
-  }
-  for (i = 0; i < numberof(CaseUnfold_11_Locale); i++) {
-    p1 = &CaseUnfold_11_Locale[i];
+  for (i = 0; i < numberof(CaseUnfold_11_Table); i++) {
+    const CaseUnfold_11_Type *p1 = &CaseUnfold_11_Table[i];
     st_add_direct(Unfold1Table, (st_data_t )p1->from, (st_data_t )&(p1->to));
   }
 
   Unfold2Table = st_init_table_with_size(&type_code2_hash, UNFOLD2_TABLE_SIZE);
   if (ONIG_IS_NULL(Unfold2Table)) return ONIGERR_MEMORY;
 
-  for (i = 0; i < numberof(CaseUnfold_12); i++) {
-    p2 = &CaseUnfold_12[i];
-    st_add_direct(Unfold2Table, (st_data_t )p2->from, (st_data_t )(&p2->to));
-  }
-  for (i = 0; i < numberof(CaseUnfold_12_Locale); i++) {
-    p2 = &CaseUnfold_12_Locale[i];
+  for (i = 0; i < numberof(CaseUnfold_12_Table); i++) {
+    const CaseUnfold_12_Type *p2 = &CaseUnfold_12_Table[i];
     st_add_direct(Unfold2Table, (st_data_t )p2->from, (st_data_t )(&p2->to));
   }
 
@@ -283,7 +267,7 @@ static int init_case_fold_table(void) https://github.com/ruby/ruby/blob/trunk/enc/unicode.c#L267
   if (ONIG_IS_NULL(Unfold3Table)) return ONIGERR_MEMORY;
 
   for (i = 0; i < numberof(CaseUnfold_13); i++) {
-    p3 = &CaseUnfold_13[i];
+    const CaseUnfold_13_Type *p3 = &CaseUnfold_13[i];
     st_add_direct(Unfold3Table, (st_data_t )p3->from, (st_data_t )(&p3->to));
   }
 

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

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