]> git.ipfire.org Git - thirdparty/vectorscan.git/commitdiff
determinise: use find first, rather than emplace
authorJustin Viiret <justin.viiret@intel.com>
Fri, 21 Jul 2017 06:43:16 +0000 (16:43 +1000)
committerMatthew Barr <matthew.barr@intel.com>
Mon, 21 Aug 2017 01:14:59 +0000 (11:14 +1000)
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

index eb56d97064b98351acd527999d2b784c6a35d16f..102a197441e58797ea28de94f481cd5920e58e73 100644 (file)
@@ -139,14 +139,16 @@ bool determinise(Auto &n, std::vector<ds> &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);