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

ruby-changes:22811

From: naruse <ko1@a...>
Date: Thu, 1 Mar 2012 01:29:19 +0900 (JST)
Subject: [ruby-changes:22811] naruse:r34860 (trunk): * regparse.c (is_onechar_cclass): optimize character class

naruse	2012-03-01 01:29:06 +0900 (Thu, 01 Mar 2012)

  New Revision: 34860

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

  Log:
    * regparse.c (is_onechar_cclass): optimize character class
      Merge Onigmo 27278c12e6674043cc8affca6507e20e119a86ee.
    
    * regparse.c (is_onechar_cclass): [bug] unexpected match occurs when a
      char class contains no char
    
    * enc/unicode.c (init_case_fold_table): define the sizes of case
      folding tables in casefold.h

  Modified files:
    trunk/ChangeLog
    trunk/enc/unicode/casefold.h
    trunk/enc/unicode.c
    trunk/regparse.c

Index: regparse.c
===================================================================
--- regparse.c	(revision 34859)
+++ regparse.c	(revision 34860)
@@ -1786,8 +1786,8 @@
 
   if (inc_n != 1) {
     if (checkdup && from <= data[low*2+1]
-	&& (data[low*2] <= from  || data[low*2+1] <= to))
-	CC_DUP_WARN(env);
+	&& (data[low*2] <= from || data[low*2+1] <= to))
+      CC_DUP_WARN(env);
     if (from > data[low*2])
       from = data[low*2];
     if (to < data[(high - 1)*2 + 1])
@@ -1799,7 +1799,7 @@
     int to_pos   = SIZE_CODE_POINT * (1 + (low + 1) * 2);
 
     if (inc_n > 0) {
-      if ((OnigCodePoint )high < n) {
+      if (high < n) {
 	int size = (n - high) * 2 * SIZE_CODE_POINT;
 	BBUF_MOVE_RIGHT(bbuf, from_pos, to_pos, size);
       }
@@ -5722,9 +5722,13 @@
       }
     }
   }
+  if (found == 0) {
+    /* the character class contains no char. */
+    return 0;
+  }
   if (j >= 0) {
     /* only one char found in the bitset, calculate the code point. */
-    c = BITS_IN_ROOM * j + (countbits(b2 - 1) & 0x1f);
+    c = BITS_IN_ROOM * j + countbits(b2 - 1);
   }
   *code = c;
   return 1;
@@ -5746,7 +5750,7 @@
   switch (tok->type) {
   case TK_ALT:
   case TK_EOT:
-    end_of_token:
+  end_of_token:
     *np = node_new_empty();
     return tok->type;
     break;
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 34859)
+++ ChangeLog	(revision 34860)
@@ -1,3 +1,14 @@
+Thu Mar  1 01:25:43 2012  NARUSE, Yui  <naruse@r...>
+
+	* regparse.c (is_onechar_cclass): optimize character class
+	  Merge Onigmo 27278c12e6674043cc8affca6507e20e119a86ee.
+
+	* regparse.c (is_onechar_cclass): [bug] unexpected match occurs when a
+	  char class contains no char
+
+	* enc/unicode.c (init_case_fold_table): define the sizes of case
+	  folding tables in casefold.h
+
 Wed Feb 29 16:11:34 2012  NAKAMURA Usaku  <usa@r...>
 
 	* win32/Makefile.sub (MAKEDIRS): use mkdir of cmd.exe instead of ruby.
Index: enc/unicode/casefold.h
===================================================================
--- enc/unicode/casefold.h	(revision 34859)
+++ enc/unicode/casefold.h	(revision 34860)
@@ -1,3 +1,6 @@
+/* DO NOT EDIT THIS FILE. */
+/* Generated by tool/CaseFolding.py */
+
 static const CaseFold_11_Type CaseFold[] = {
  { 0x0041, {1, {0x0061}}},
  { 0x0042, {1, {0x0062}}},
@@ -2228,3 +2231,8 @@
  { {0x03c5, 0x0313, 0x0342}, {1, {0x1f56 }}},
  { {0x03c9, 0x0342, 0x03b9}, {1, {0x1ff7 }}},
 };
+
+#define FOLD_TABLE_SIZE		1357
+#define UNFOLD1_TABLE_SIZE	1207
+#define UNFOLD2_TABLE_SIZE	88
+#define UNFOLD3_TABLE_SIZE	23
Index: enc/unicode.c
===================================================================
--- enc/unicode.c	(revision 34859)
+++ enc/unicode.c	(revision 34860)
@@ -238,7 +238,7 @@
 
   THREAD_ATOMIC_START;
 
-  FoldTable = st_init_numtable_with_size(1400);
+  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];
@@ -249,7 +249,7 @@
     st_add_direct(FoldTable, (st_data_t )p->from, (st_data_t )&(p->to));
   }
 
-  Unfold1Table = st_init_numtable_with_size(1200);
+  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++) {
@@ -261,7 +261,7 @@
     st_add_direct(Unfold1Table, (st_data_t )p1->from, (st_data_t )&(p1->to));
   }
 
-  Unfold2Table = st_init_table_with_size(&type_code2_hash, 200);
+  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++) {
@@ -273,7 +273,7 @@
     st_add_direct(Unfold2Table, (st_data_t )p2->from, (st_data_t )(&p2->to));
   }
 
-  Unfold3Table = st_init_table_with_size(&type_code3_hash, 30);
+  Unfold3Table = st_init_table_with_size(&type_code3_hash, UNFOLD3_TABLE_SIZE);
   if (ONIG_IS_NULL(Unfold3Table)) return ONIGERR_MEMORY;
 
   for (i = 0; i < numberof(CaseUnfold_13); i++) {

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

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