From 4528485a560d83a5d8d89bfd7c5d8d7b5db4f45d Mon Sep 17 00:00:00 2001 From: Justin Viiret Date: Fri, 21 Jul 2017 16:43:16 +1000 Subject: [PATCH] determinise: use find first, rather than emplace For non-trivial StateSet types, copying to do the emplace if it is already in the map is more expensive than checking with find() first. --- src/util/determinise.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/util/determinise.h b/src/util/determinise.h index eb56d970..102a1974 100644 --- a/src/util/determinise.h +++ b/src/util/determinise.h @@ -139,14 +139,16 @@ bool determinise(Auto &n, std::vector &dstates, size_t state_limit, if (s && succs[s] == succs[s - 1]) { succ_id = dstates[curr_id].next[s - 1]; } else { - auto p = dstate_ids.emplace(succs[s], dstates.size()); - succ_id = p.first->second; - if (!p.second) { /* succs[s] is already present */ + auto p = dstate_ids.find(succs[s]); + if (p != dstate_ids.end()) { // succ[s] is already present + succ_id = p->second; if (succ_id > curr_id && !dstates[succ_id].daddy && n.unalpha[s] < N_CHARS) { dstates[succ_id].daddy = curr_id; } } else { + succ_id = dstate_ids.size(); + dstate_ids.emplace(succs[s], succ_id); dstates.push_back(ds(alphabet_size)); dstates.back().daddy = n.unalpha[s] < N_CHARS ? curr_id : 0; q.emplace(succs[s], succ_id);