From a11ca79fc7182088bcdc8f7882384292fb1bb931 Mon Sep 17 00:00:00 2001 From: Ulya Trofimovich Date: Wed, 28 Sep 2016 14:14:55 +0100 Subject: [PATCH] Sort closure right after construction. --- re2c/src/ir/dfa/closure.cc | 5 ++++- re2c/src/ir/dfa/closure.h | 10 ---------- re2c/src/ir/dfa/find_state.cc | 5 +---- re2c/src/ir/dfa/find_state.h | 2 +- 4 files changed, 6 insertions(+), 16 deletions(-) diff --git a/re2c/src/ir/dfa/closure.cc b/re2c/src/ir/dfa/closure.cc index b2ce41d3..8ed458a7 100644 --- a/re2c/src/ir/dfa/closure.cc +++ b/re2c/src/ir/dfa/closure.cc @@ -1,4 +1,4 @@ -#include +#include #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] diff --git a/re2c/src/ir/dfa/closure.h b/re2c/src/ir/dfa/closure.h index 08c45d7e..9cf56657 100644 --- a/re2c/src/ir/dfa/closure.h +++ b/re2c/src/ir/dfa/closure.h @@ -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; diff --git a/re2c/src/ir/dfa/find_state.cc b/re2c/src/ir/dfa/find_state.cc index fd608070..2ab0637a 100644 --- a/re2c/src/ir/dfa/find_state.cc +++ b/re2c/src/ir/dfa/find_state.cc @@ -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); } diff --git a/re2c/src/ir/dfa/find_state.h b/re2c/src/ir/dfa/find_state.h index 68862c64..039c9ec9 100644 --- a/re2c/src/ir/dfa/find_state.h +++ b/re2c/src/ir/dfa/find_state.h @@ -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 -- 2.40.0