]> granicus.if.org Git - re2c/commitdiff
Sort closure right after construction.
authorUlya Trofimovich <skvadrik@gmail.com>
Wed, 28 Sep 2016 13:14:55 +0000 (14:14 +0100)
committerUlya Trofimovich <skvadrik@gmail.com>
Wed, 28 Sep 2016 13:14:55 +0000 (14:14 +0100)
re2c/src/ir/dfa/closure.cc
re2c/src/ir/dfa/closure.h
re2c/src/ir/dfa/find_state.cc
re2c/src/ir/dfa/find_state.h

index b2ce41d3fb2915b3a368040652c685437592369e..8ed458a75e2250f5f5c6e79ea21e451ef68f7f70 100644 (file)
@@ -1,4 +1,4 @@
-#include <string.h>
+#include <algorithm>
 
 #include "src/ir/dfa/closure.h"
 #include "src/ir/nfa/nfa.h"
@@ -21,6 +21,9 @@ void closure(const closure_t &clos1, closure_t &clos2,
        }
 
        prune_final_items(clos2, rules);
+
+       // sort closure: we need this to compare closures by hash
+       std::sort(clos2.begin(), clos2.end(), compare_by_rule);
 }
 
 /* note [epsilon-closures in tagged NFA]
index 08c45d7ef3c7a188ca0339114a887c96baab7a36..9cf566573f8acfe9d460bd28a8d4d955916293da 100644 (file)
@@ -16,7 +16,6 @@ struct clos_t
 
        inline clos_t();
        inline clos_t(nfa_state_t *s, size_t i);
-       static inline bool compare(const clos_t &c1, const clos_t &c2);
        static inline bool final(const clos_t &c);
        static inline bool not_final(const clos_t &c);
 };
@@ -39,15 +38,6 @@ clos_t::clos_t(nfa_state_t *s, size_t i)
        , tagidx(i)
 {}
 
-bool clos_t::compare(const clos_t &c1, const clos_t &c2)
-{
-       const nfa_state_t
-               *s1 = c1.state,
-               *s2 = c2.state;
-       return s1 < s2
-               || (s1 == s2 && c1.tagidx < c2.tagidx);
-}
-
 bool clos_t::final(const clos_t &c)
 {
        return c.state->type == nfa_state_t::FIN;
index fd608070f6b955d679e71f52df3247cebee943ea..2ab0637a628b7c1a7b0f82ae26abe7db38addae0 100644 (file)
@@ -68,16 +68,13 @@ size_t clospool_t::insert(const closure_t &clos)
        return lookup.push(hash, new closure_t(clos));
 }
 
-size_t find_state(closure_t &clos, clospool_t &clospool)
+size_t find_state(const closure_t &clos, clospool_t &clospool)
 {
        // empty closure corresponds to default state
        if (clos.empty()) {
                return dfa_t::NIL;
        }
 
-       // sort closure to allow comparison by hash and 'memcmp'
-       std::sort(clos.begin(), clos.end(), clos_t::compare);
-
        return clospool.insert(clos);
 }
 
index 68862c64c86221c387ef7819c5f2d1dd49723f01..039c9ec97765d21e0e893be6bb30cffb996b84c4 100644 (file)
@@ -23,7 +23,7 @@ public:
        size_t insert(const closure_t &clos);
 };
 
-size_t find_state(closure_t &clos, clospool_t &clospool);
+size_t find_state(const closure_t &clos, clospool_t &clospool);
 
 } // namespace re2c