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.
This commit is contained in:
Justin Viiret 2017-07-21 16:43:16 +10:00 committed by Matthew Barr
parent 33823d60d1
commit 4528485a56

View File

@ -139,14 +139,16 @@ bool determinise(Auto &n, std::vector<ds> &dstates, size_t state_limit,
if (s && succs[s] == succs[s - 1]) { if (s && succs[s] == succs[s - 1]) {
succ_id = dstates[curr_id].next[s - 1]; succ_id = dstates[curr_id].next[s - 1];
} else { } else {
auto p = dstate_ids.emplace(succs[s], dstates.size()); auto p = dstate_ids.find(succs[s]);
succ_id = p.first->second; if (p != dstate_ids.end()) { // succ[s] is already present
if (!p.second) { /* succs[s] is already present */ succ_id = p->second;
if (succ_id > curr_id && !dstates[succ_id].daddy if (succ_id > curr_id && !dstates[succ_id].daddy
&& n.unalpha[s] < N_CHARS) { && n.unalpha[s] < N_CHARS) {
dstates[succ_id].daddy = curr_id; dstates[succ_id].daddy = curr_id;
} }
} else { } else {
succ_id = dstate_ids.size();
dstate_ids.emplace(succs[s], succ_id);
dstates.push_back(ds(alphabet_size)); dstates.push_back(ds(alphabet_size));
dstates.back().daddy = n.unalpha[s] < N_CHARS ? curr_id : 0; dstates.back().daddy = n.unalpha[s] < N_CHARS ? curr_id : 0;
q.emplace(succs[s], succ_id); q.emplace(succs[s], succ_id);