]> granicus.if.org Git - re2c/commitdiff
Use distinct type for path suffixes during skeleton data generation.
authorUlya Trofimovich <skvadrik@gmail.com>
Wed, 16 Mar 2016 12:20:25 +0000 (12:20 +0000)
committerUlya Trofimovich <skvadrik@gmail.com>
Wed, 16 Mar 2016 12:20:25 +0000 (12:20 +0000)
re2c/src/ir/skeleton/generate_data.cc
re2c/src/ir/skeleton/path.h
re2c/src/ir/skeleton/skeleton.cc
re2c/src/ir/skeleton/skeleton.h

index d4bb59475d20cd15060cd182a9efb31bd58f729e..7e1a582a158bb0f3e0848ca6cd41418c06e448ef 100644 (file)
@@ -147,16 +147,17 @@ template <typename cunit_t, typename key_t> static void cover(
 {
        const Node &node = skel.nodes[i];
        uint8_t &loop = skel.loops[i];
-       path_t *&suffix = skel.suffixes[i];
+       suffix_t *&suffix = skel.suffixes[i];
 
        if (node.end() && suffix == NULL) {
-               suffix = new path_t(i);
+               suffix = new suffix_t;
        }
 
        if (suffix != NULL)
        {
-               prefix.append(suffix);
+               prefix.push_sfx(*suffix);
                size = size + cover_one<cunit_t, key_t>(skel, input, keys, prefix);
+               prefix.pop_sfx(*suffix);
        } else if (loop < 2) {
                local_inc _(loop);
                Node::arcs_t::const_iterator
@@ -165,15 +166,14 @@ template <typename cunit_t, typename key_t> static void cover(
                for (; arc != end && !size.overflow(); ++arc) {
                        const size_t j = arc->first;
 
-                       path_t new_prefix = prefix;
-                       new_prefix.push(j);
-                       cover<cunit_t, key_t>(skel, input, keys, new_prefix, size, j);
+                       prefix.push(j);
+                       cover<cunit_t, key_t>(skel, input, keys, prefix, size, j);
+                       prefix.pop();
 
-                       const path_t *sfx = skel.suffixes[j];
+                       const suffix_t *sfx = skel.suffixes[j];
                        if (sfx != NULL && suffix == NULL) {
-                               suffix = new path_t(i);
+                               suffix = new suffix_t(*sfx);
                                suffix->push(j);
-                               suffix->append(sfx);
                        }
                }
        }
index a5865b228699df615f7fa442b3f36aaf533d55a8..f5709c5e149bf8be7dae7ba55aef4122fc751b8d 100644 (file)
@@ -9,6 +9,19 @@
 namespace re2c
 {
 
+class suffix_t
+{
+       std::vector<size_t> arcs;
+
+public:
+       suffix_t() : arcs() {}
+       void push(size_t i)
+       {
+               arcs.push_back(i);
+       }
+       friend class path_t;
+};
+
 class path_t
 {
        std::vector<size_t> arcs;
@@ -78,10 +91,13 @@ public:
        {
                arcs.pop_back();
        }
-       void append(const path_t *p)
+       void push_sfx(const suffix_t &suffix)
+       {
+               arcs.insert(arcs.end(), suffix.arcs.rbegin(), suffix.arcs.rend());
+       }
+       void pop_sfx(const suffix_t &suffix)
        {
-               assert(arcs.back() == p->arcs.front());
-               arcs.insert(arcs.end(), p->arcs.begin() + 1, p->arcs.end());
+               arcs.resize(arcs.size() - suffix.arcs.size());
        }
        bool operator<(const path_t &p) const
        {
index 7baa656adb497178a76a5062f112bebb2ff8af8a..0664b1083df4a6e0ff356b21bf2073064a0456df 100644 (file)
@@ -65,12 +65,12 @@ Skeleton::Skeleton(
                nodes_count(dfa.states.size() + 1), // +1 for default state
                nodes(new Node[nodes_count]),
                loops(new uint8_t[nodes_count]),
-               suffixes(new path_t*[nodes_count]),
+               suffixes(new suffix_t*[nodes_count]),
                sizeof_key(4),
                rules(rs)
 {
        memset(loops, 0, sizeof(uint8_t) * nodes_count);
-       memset(suffixes, 0, sizeof(path_t*) * nodes_count);
+       memset(suffixes, 0, sizeof(suffix_t*) * nodes_count);
 
        const size_t nc = cs.size() - 1;
 
index 93460ed8a9bf60c407037c60a2a2ade578eea187..856fd853cf4d331012172f1d6cec3571acb0ec28 100644 (file)
@@ -21,6 +21,7 @@ namespace re2c
 struct dfa_t;
 struct OutputFile;
 struct path_t;
+struct suffix_t;
 
 typedef local_increment_t<uint8_t> local_inc;
 
@@ -58,7 +59,7 @@ struct Skeleton
        uint8_t *loops;
 
        // paths to end node (for constructing path cover)
-       path_t **suffixes;
+       suffix_t **suffixes;
 
        size_t sizeof_key;
        rules_t rules;