]> granicus.if.org Git - re2c/commitdiff
libre2c_posix: another small improvement in regexec() implementation.
authorUlya Trofimovich <skvadrik@gmail.com>
Sun, 27 Jan 2019 22:57:25 +0000 (22:57 +0000)
committerUlya Trofimovich <skvadrik@gmail.com>
Sun, 27 Jan 2019 22:57:25 +0000 (22:57 +0000)
re2c/libre2c_posix/regexec.cc

index 788d79b0279850db978c1e83b90663ab225c1a90..9923569339aa73e59ec71bb3ef2e62462cdc7e58 100644 (file)
@@ -59,13 +59,15 @@ int regexec(const regex_t *preg, const char *string, size_t nmatch,
     }
 
     if (s->rule != Rule::NONE) {
+        regmatch_t *m = pmatch;
         result = 0;
         const regoff_t mlen = p - string - 1;
 
         apply_regops(regs, s->tcmd[dfa->nchars], mlen);
 
-        pmatch[0].rm_so = 0;
-        pmatch[0].rm_eo = mlen;
+        m->rm_so = 0;
+        m->rm_eo = mlen;
+        ++m;
 
         const Rule &rule = dfa->rules[0];
         for (size_t t = rule.ltag; t < rule.htag; ++t) {
@@ -85,8 +87,13 @@ int regexec(const regex_t *preg, const char *string, size_t nmatch,
                 off -= static_cast<regoff_t>(tag.dist);
             }
 
-            regmatch_t *rm = &pmatch[tag.ncap / 2 + 1];
-            *((tag.ncap % 2 == 0) ? &rm->rm_so : &rm->rm_eo) = off;
+            if (tag.ncap % 2 == 0) {
+                m->rm_so = off;
+            }
+            else {
+                m->rm_eo = off;
+                ++m;
+            }
         }
     }