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

ruby-changes:24021

From: naruse <ko1@a...>
Date: Thu, 14 Jun 2012 05:48:34 +0900 (JST)
Subject: [ruby-changes:24021] naruse:r36072 (trunk): * regparse.c (PFETCH_READY): suppress Wunused-but-set-variable.

naruse	2012-06-14 05:46:11 +0900 (Thu, 14 Jun 2012)

  New Revision: 36072

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

  Log:
    * regparse.c (PFETCH_READY): suppress Wunused-but-set-variable.
    
    * regparse.c (is_onechar_cclass): restructured to clarify that c is
      used iff found == 1.

  Modified files:
    trunk/ChangeLog
    trunk/regparse.c

Index: regparse.c
===================================================================
--- regparse.c	(revision 36071)
+++ regparse.c	(revision 36072)
@@ -264,8 +264,8 @@
 #define PEND_VALUE   0
 
 #ifdef __GNUC__
-/* get rid of Wunused-but-set-variable */
-#define PFETCH_READY  UChar* pfetch_prev = NULL
+/* get rid of Wunused-but-set-variable and Wuninitialized */
+#define PFETCH_READY  UChar* pfetch_prev = NULL; (void)pfetch_prev
 #else
 #define PFETCH_READY  UChar* pfetch_prev
 #endif
@@ -5684,10 +5684,9 @@
 static int
 is_onechar_cclass(CClassNode* cc, OnigCodePoint* code)
 {
-  OnigCodePoint c;
+  OnigCodePoint c; /* c is used iff found == 1 */
   int found = 0;
-  int i, j = -1;
-  Bits b1, b2;
+  int i;
   BBuf *bbuf = cc->mbuf;
 
   if (IS_NCCLASS_NOT(cc)) return 0;
@@ -5699,42 +5698,37 @@
     data = (OnigCodePoint* )(bbuf->p) + 1;
     if ((n == 1) && (data[0] == data[1])) {
       /* only one char found in the bbuf, save the code point. */
-      found = 1;
       c = data[0];
+      if ((c >= SINGLE_BYTE_SIZE) || !BITSET_AT(cc->bs, c)) {
+        /* set found=1 if c is not included in the bitset */
+        found = 1;
+      }
     }
     else {
       return 0;  /* the bbuf contains multiple chars */
     }
   }
 
-  if (found && (c < SINGLE_BYTE_SIZE) && BITSET_AT(cc->bs, c)) {
-    /* c is included in the bitset, ignore the result of bbuf. */
-    found = 0;
-  }
-
   /* check bitset */
   for (i = 0; i < (int )BITSET_SIZE; i++) {
-    b1 = cc->bs[i];
+    Bits b1 = cc->bs[i];
     if (b1 != 0) {
       if (((b1 & (b1 - 1)) == 0) && (found == 0)) {
         found = 1;
-        j = i;
-        b2 = b1;
+        c = BITS_IN_ROOM * i + countbits(b1 - 1);
       } else {
         return 0;  /* the character class contains multiple chars */
       }
     }
   }
-  if (found == 0) {
-    /* the character class contains no char. */
-    return 0;
+
+  if (found) {
+    *code = c;
+    return 1;
   }
-  if (j >= 0) {
-    /* only one char found in the bitset, calculate the code point. */
-    c = BITS_IN_ROOM * j + countbits(b2 - 1);
-  }
-  *code = c;
-  return 1;
+
+  /* the character class contains no char. */
+  return 0;
 }
 
 
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 36071)
+++ ChangeLog	(revision 36072)
@@ -1,3 +1,10 @@
+Thu Jun 14 05:23:05 2012  NARUSE, Yui  <naruse@r...>
+
+	* regparse.c (PFETCH_READY): suppress Wunused-but-set-variable.
+
+	* regparse.c (is_onechar_cclass): restructured to clarify that c is
+	  used iff found == 1.
+
 Thu Jun 14 02:54:17 2012  NARUSE, Yui  <naruse@r...>
 
 	* configure.in: use -fbuiltin with -ansi -std=iso9899:199409.

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

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