]> granicus.if.org Git - re2c/commitdiff
Don't use a dedicated struct for returning multiple values from function.
authorUlya Trofimovich <skvadrik@gmail.com>
Fri, 10 Aug 2018 23:32:11 +0000 (00:32 +0100)
committerUlya Trofimovich <skvadrik@gmail.com>
Fri, 10 Aug 2018 23:32:11 +0000 (00:32 +0100)
re2c/src/dfa/find_state.cc
re2c/src/dfa/find_state.h

index 9ccffe3798ff4d1b9a6c44c4ba4439c1d5f5100a..08a5c68b83a193d209242376ae26b463ab9f0cd1 100644 (file)
@@ -307,14 +307,18 @@ bool kernels_t::operator()(const kernel_t *x, const kernel_t *y)
  * more complex analysis (and are not so useful after all), so we drop them.
  */
 
-kernels_t::result_t kernels_t::insert(const closure_t &clos,
-       tcmd_t *acts, tagver_t maxver, const prectable_t *prectbl)
+size_t kernels_t::insert(const closure_t &clos, tagver_t maxver,
+       const prectable_t *prectbl, tcmd_t *&acts, bool &is_new)
 {
        const size_t nkern = clos.size();
        size_t x = dfa_t::NIL;
+       is_new = false;
 
        // empty closure corresponds to default state
-       if (nkern == 0) return result_t(x, NULL, false);
+       if (nkern == 0) {
+               acts = NULL;
+               return x;
+       }
 
        // resize buffer if closure is too large
        reserve_buffers(buffers, tagpool.alc, maxver, nkern);
@@ -340,17 +344,18 @@ kernels_t::result_t kernels_t::insert(const closure_t &clos,
        // try to find identical kernel
        kernel_eq_t cmp_eq = {tagpool, tags};
        x = lookup.find_with(hash, k, cmp_eq);
-       if (x != index_t::NIL) return result_t(x, acts, false);
+       if (x != index_t::NIL) return x;
 
        // else try to find mappable kernel
        // see note [bijective mappings]
        this->pacts = &acts;
        x = lookup.find_with(hash, k, *this);
-       if (x != index_t::NIL) return result_t(x, acts, false);
+       if (x != index_t::NIL) return x;
 
        // otherwise add new kernel
        x = lookup.push(hash, make_kernel_copy(k, tagpool.alc));
-       return result_t(x, acts, true);
+       is_new = true;
+       return x;
 }
 
 static tcmd_t *finalizer(const clos_t &clos, size_t ridx,
@@ -385,13 +390,13 @@ static tcmd_t *finalizer(const clos_t &clos, size_t ridx,
        return copy;
 }
 
-void find_state(dfa_t &dfa, size_t state, size_t symbol, kernels_t &kernels,
+void find_state(dfa_t &dfa, size_t origin, size_t symbol, kernels_t &kernels,
        const closure_t &closure, tcmd_t *acts, dump_dfa_t &dump, const prectable_t *prectbl)
 {
-       const kernels_t::result_t
-               result = kernels.insert(closure, acts, dfa.maxtagver, prectbl);
+       bool is_new;
+       const size_t state = kernels.insert(closure, dfa.maxtagver, prectbl, acts, is_new);
 
-       if (result.isnew) {
+       if (is_new) {
                // create new DFA state
                dfa_state_t *t = new dfa_state_t(dfa.nchars);
                dfa.states.push_back(t);
@@ -404,18 +409,18 @@ void find_state(dfa_t &dfa, size_t state, size_t symbol, kernels_t &kernels,
                        t->rule = c->state->rule;
                        t->tcmd[dfa.nchars] = finalizer(*c, t->rule, dfa,
                                kernels.tagpool, kernels.tags);
-                       dump.final(result.state, c->state);
+                       dump.final(state, c->state);
                }
        }
 
-       if (state == dfa_t::NIL) { // initial state
-               dfa.tcmd0 = result.cmd;
+       if (origin == dfa_t::NIL) { // initial state
+               dfa.tcmd0 = acts;
                dump.state0(closure);
        } else {
-               dfa_state_t *s = dfa.states[state];
-               s->arcs[symbol] = result.state;
-               s->tcmd[symbol] = result.cmd;
-               dump.state(closure, state, symbol, result.isnew);
+               dfa_state_t *s = dfa.states[origin];
+               s->arcs[symbol] = state;
+               s->tcmd[symbol] = acts;
+               dump.state(closure, origin, symbol, is_new);
        }
 }
 
index 403d0ace9ddb90fc025731f3933aec03c2e1621d..c889effb478bbecabcce075b32795754c63fc701 100644 (file)
@@ -51,20 +51,6 @@ struct kernel_buffers_t
 
 struct kernels_t
 {
-       struct result_t
-       {
-               size_t state;
-               tcmd_t *cmd;
-               bool isnew;
-
-               result_t(size_t s, tcmd_t *p, bool n)
-                       : state(s)
-                       , cmd(p)
-                       , isnew(n)
-               {}
-       };
-
-private:
        typedef lookup_t<const kernel_t*> index_t;
        index_t lookup;
 
@@ -82,7 +68,7 @@ public:
        kernels_t(Tagpool &tagp, tcpool_t &tcp, const std::vector<Tag> &ts);
        inline size_t size() const { return lookup.size(); }
        inline const kernel_t* operator[](size_t idx) const { return lookup[idx]; }
-       result_t insert(const closure_t &clos, tcmd_t *acts, tagver_t maxver, const prectable_t *prectbl);
+       size_t insert(const closure_t &clos, tagver_t maxver, const prectable_t *prectbl, tcmd_t *&acts, bool &is_new);
        bool operator()(const kernel_t *k1, const kernel_t *k2);
        FORBID_COPY(kernels_t);
 };