From: Ulya Trofimovich Date: Thu, 14 Feb 2019 13:10:42 +0000 (+0000) Subject: libre2c: use preallocated buffer. X-Git-Tag: 1.2~172 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=971eedbf9774e6364ac632ffcc2878946cd82879;p=re2c libre2c: use preallocated buffer. --- diff --git a/re2c/lib/regexec.cc b/re2c/lib/regexec.cc index 349dea80..2935d7d2 100644 --- a/re2c/lib/regexec.cc +++ b/re2c/lib/regexec.cc @@ -38,32 +38,29 @@ int finalize(const simctx_t &ctx, const char *string, size_t nmatch, m->rm_eo = ctx.marker - string - 1; const std::vector &tags = ctx.nfa->tags; - size_t todo = nmatch * 2, ntags = tags.size(); - bool *done = new bool[ntags]; - memset(done, 0, ntags * sizeof(bool)); + size_t todo = nmatch * 2; + bool *done = ctx.done; + memset(done, 0, ctx.nsub * sizeof(bool)); for (size_t i = ctx.hidx; todo > 0 && i != HROOT; ) { const history_t::node_t &n = ctx.hist.nodes[i]; - const size_t t = n.info.idx; - if (!done[t]) { + const Tag &tag = tags[n.info.idx]; + const size_t t = tag.ncap; + if (!fictive(tag) && t < nmatch * 2 && !done[t]) { done[t] = true; - const Tag &tag = tags[t]; - if (!fictive(tag) && tag.ncap < nmatch * 2) { - --todo; - const regoff_t off = n.info.neg ? -1 : static_cast(n.step); - m = &pmatch[tag.ncap / 2 + 1]; - if (tag.ncap % 2 == 0) { - m->rm_so = off; - } - else { - m->rm_eo = off; - } + --todo; + const regoff_t off = n.info.neg ? -1 : static_cast(n.step); + m = &pmatch[t / 2 + 1]; + if (t % 2 == 0) { + m->rm_so = off; + } + else { + m->rm_eo = off; } } i = n.pred; } - delete[] done; return 0; }