[Groonga-commit] groonga/groonga at 84e2574 [master] grn_pat: simplify a loop

Back to archive index

susumu.yata null+****@clear*****
Tue Oct 13 12:28:29 JST 2015


susumu.yata	2015-10-13 12:28:29 +0900 (Tue, 13 Oct 2015)

  New Revision: 84e2574f430121e5490c90eb31ff6b269efe2377
  https://github.com/groonga/groonga/commit/84e2574f430121e5490c90eb31ff6b269efe2377

  Message:
    grn_pat: simplify a loop

  Modified files:
    lib/pat.c

  Modified: lib/pat.c (+40 -44)
===================================================================
--- lib/pat.c    2015-10-13 12:01:06 +0900 (6c1d334)
+++ lib/pat.c    2015-10-13 12:28:29 +0900 (841f40e)
@@ -1679,55 +1679,51 @@ grn_pat_cursor_next(grn_ctx *ctx, grn_pat_cursor *c)
   while ((se = pop(c))) {
     grn_id id = se->id;
     int check = se->check, ch;
-    for (;;) {
-      if (id) {
-        PAT_AT(c->pat, id, node);
-        if (node) {
-          ch = PAT_CHK(node);
-          if (ch > check) {
-            if (c->obj.header.flags & GRN_CURSOR_DESCENDING) {
-              push(c, node->lr[0], ch);
-              id = node->lr[1];
-            } else {
-              push(c, node->lr[1], ch);
-              id = node->lr[0];
-            }
-            check = ch;
-            continue;
+    while (id) {
+      PAT_AT(c->pat, id, node);
+      if (node) {
+        ch = PAT_CHK(node);
+        if (ch > check) {
+          if (c->obj.header.flags & GRN_CURSOR_DESCENDING) {
+            push(c, node->lr[0], ch);
+            id = node->lr[1];
           } else {
-            if (id == c->tail) {
-              c->sp = 0;
-            } else {
-              if (!c->curr_rec && c->tail) {
-                uint32_t lmin, lmax;
-                pat_node *nmin, *nmax;
-                const uint8_t *kmin, *kmax;
-                if (c->obj.header.flags & GRN_CURSOR_DESCENDING) {
-                  PAT_AT(c->pat, c->tail, nmin);
-                  PAT_AT(c->pat, id, nmax);
-                } else {
-                  PAT_AT(c->pat, id, nmin);
-                  PAT_AT(c->pat, c->tail, nmax);
-                }
-                lmin = PAT_LEN(nmin);
-                lmax = PAT_LEN(nmax);
-                kmin = pat_node_get_key(ctx, c->pat, nmin);
-                kmax = pat_node_get_key(ctx, c->pat, nmax);
-                if ((lmin < lmax) ?
-                    (memcmp(kmin, kmax, lmin) > 0) :
-                    (memcmp(kmin, kmax, lmax) >= 0)) {
-                  c->sp = 0;
-                  break;
-                }
+            push(c, node->lr[1], ch);
+            id = node->lr[0];
+          }
+          check = ch;
+          continue;
+        } else {
+          if (id == c->tail) {
+            c->sp = 0;
+          } else {
+            if (!c->curr_rec && c->tail) {
+              uint32_t lmin, lmax;
+              pat_node *nmin, *nmax;
+              const uint8_t *kmin, *kmax;
+              if (c->obj.header.flags & GRN_CURSOR_DESCENDING) {
+                PAT_AT(c->pat, c->tail, nmin);
+                PAT_AT(c->pat, id, nmax);
+              } else {
+                PAT_AT(c->pat, id, nmin);
+                PAT_AT(c->pat, c->tail, nmax);
+              }
+              lmin = PAT_LEN(nmin);
+              lmax = PAT_LEN(nmax);
+              kmin = pat_node_get_key(ctx, c->pat, nmin);
+              kmax = pat_node_get_key(ctx, c->pat, nmax);
+              if ((lmin < lmax) ?
+                  (memcmp(kmin, kmax, lmin) > 0) :
+                  (memcmp(kmin, kmax, lmax) >= 0)) {
+                c->sp = 0;
+                break;
               }
             }
-            c->curr_rec = id;
-            c->rest--;
-            return id;
           }
+          c->curr_rec = id;
+          c->rest--;
+          return id;
         }
-      } else {
-        break;
       }
     }
   }
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index