From: Ulya Trofimovich Date: Thu, 27 Oct 2016 13:56:06 +0000 (+0100) Subject: Constified comparison predicate in lookup table. X-Git-Tag: 1.0~39^2~246 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c34d3ce6bd11c599c28bf8ac615df85234ff6ba2;p=re2c Constified comparison predicate in lookup table. --- diff --git a/re2c/src/ir/dfa/tag_indexing.cc b/re2c/src/ir/dfa/tag_indexing.cc index b154d30a..916a26cf 100644 --- a/re2c/src/ir/dfa/tag_indexing.cc +++ b/re2c/src/ir/dfa/tag_indexing.cc @@ -63,8 +63,7 @@ void doindex(cmd_t **pcmd, lookup_t &index) // find in or add to index const uint32_t hash = cmd_t::hash(cmd); - cmp_t cmp; - size_t idx = index.find_with(hash, cmd, cmp); + size_t idx = index.find_with(hash, cmd, cmp_t()); if (idx == lookup_t::NIL) { idx = index.push(hash, cmd); } diff --git a/re2c/src/ir/tag.cc b/re2c/src/ir/tag.cc index 5e665fea..391761ed 100644 --- a/re2c/src/ir/tag.cc +++ b/re2c/src/ir/tag.cc @@ -15,7 +15,7 @@ struct eqtag_t size_t ntags; explicit eqtag_t(size_t n): ntags(n) {} - inline tagver_t operator()(const tagver_t *x, const tagver_t *y) + inline tagver_t operator()(const tagver_t *x, const tagver_t *y) const { return memcmp(x, y, ntags * sizeof(tagver_t)) == 0; } @@ -72,8 +72,7 @@ size_t Tagpool::insert(const tagver_t *tags) const size_t size = ntags * sizeof(tagver_t); const uint32_t hash = hash32(0, tags, size); - eqtag_t eq(ntags); - const size_t idx = lookup.find_with(hash, tags, eq); + const size_t idx = lookup.find_with(hash, tags, eqtag_t(ntags)); if (idx != taglookup_t::NIL) { return idx; } diff --git a/re2c/src/util/lookup.h b/re2c/src/util/lookup.h index 10676b97..70091d52 100644 --- a/re2c/src/util/lookup.h +++ b/re2c/src/util/lookup.h @@ -39,7 +39,7 @@ public: const data_t& operator[](size_t idx) const; size_t push(hash_t h, const data_t &data); template - size_t find_with(hash_t h, const data_t &data, pred_t &pred) const; + size_t find_with(hash_t h, const data_t &data, const pred_t &pred) const; private: size_t head(hash_t) const; @@ -90,7 +90,7 @@ size_t lookup_t::push(hash_t h, const data_t &data) template template -size_t lookup_t::find_with(hash_t h, const data_t &data, pred_t &pred) const +size_t lookup_t::find_with(hash_t h, const data_t &data, const pred_t &pred) const { for (size_t i = head(h); i != NIL;) { const elem_t &e = elems[i];