From: Ulya Trofimovich Date: Mon, 10 Aug 2015 08:58:10 +0000 (+0100) Subject: Allow generic container to have size_t elements rather than uint32_t. X-Git-Tag: 0.15~149 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=98dc7e4a28e256d841778070f622b800dcfa10a6;p=re2c Allow generic container to have size_t elements rather than uint32_t. Cast to uint32_t in those use cases when we are sure that container only contains some few elements. --- diff --git a/re2c/src/codegen/emit_action.cc b/re2c/src/codegen/emit_action.cc index bc9717e1..20212711 100644 --- a/re2c/src/codegen/emit_action.cc +++ b/re2c/src/codegen/emit_action.cc @@ -168,7 +168,7 @@ void emit_accept_binary (OutputFile & o, uint32_t ind, bool & readCh, const Stat void emit_accept (OutputFile & o, uint32_t ind, bool & readCh, const State * const s, const accept_t & accepts) { - const uint32_t accepts_size = accepts.size (); + const uint32_t accepts_size = static_cast (accepts.size ()); if (accepts_size > 0) { if (!DFlag) diff --git a/re2c/src/codegen/prepare_dfa.cc b/re2c/src/codegen/prepare_dfa.cc index 1b72b7d8..cc9b197a 100644 --- a/re2c/src/codegen/prepare_dfa.cc +++ b/re2c/src/codegen/prepare_dfa.cc @@ -222,7 +222,7 @@ void DFA::prepare(OutputFile & o, uint32_t & max_fill, const std::string & cond) { if (!s->go.span[i].to->rule && s->go.span[i].to->action.type != Action::RULE) { - const uint32_t accept = accepts.find_or_add (rules[s->rule->rank]); + const uint32_t accept = static_cast (accepts.find_or_add (rules[s->rule->rank])); s->action.set_save (accept); } } diff --git a/re2c/src/util/uniq_vector.h b/re2c/src/util/uniq_vector.h index bb8c2918..76c0512f 100644 --- a/re2c/src/util/uniq_vector.h +++ b/re2c/src/util/uniq_vector.h @@ -3,14 +3,12 @@ #include -#include "src/util/c99_stdint.h" - namespace re2c { // wrapper over std::vector // O(n) lookup -// O(n^2) insertion +// O(n) insertion template class uniq_vector_t { @@ -20,18 +18,18 @@ public: uniq_vector_t () : elems () {} - uint32_t size () const + size_t size () const { return elems.size (); } - const value_t & operator [] (uint32_t i) const + const value_t & operator [] (size_t i) const { return elems[i]; } - uint32_t find_or_add (const value_t & v) + size_t find_or_add (const value_t & v) { - const uint32_t size = elems.size (); - for (uint32_t i = 0; i < size; ++i) + const size_t size = elems.size (); + for (size_t i = 0; i < size; ++i) { if (elems[i] == v) {