]> git.ipfire.org Git - thirdparty/vectorscan.git/commitdiff
rose_build_lookaround: use vector in trimLiterals
authorJustin Viiret <justin.viiret@intel.com>
Thu, 3 Aug 2017 01:33:42 +0000 (11:33 +1000)
committerMatthew Barr <matthew.barr@intel.com>
Mon, 21 Aug 2017 01:24:52 +0000 (11:24 +1000)
src/rose/rose_build_lookaround.cpp

index dd495fd31bef7d79b3381625e5a440a40412bfba..7cc1c584d66d04d6b66686e09d08bebb3d7967dd 100644 (file)
@@ -485,19 +485,17 @@ vector<LookProto> findLiteralReach(const rose_literal_id &lit) {
 }
 
 static
-map<s32, CharReach> findLiteralReach(const RoseBuildImpl &build,
-                                     const RoseVertex v) {
+vector<LookProto> findLiteralReach(const RoseBuildImpl &build,
+                                   const RoseVertex v) {
     bool first = true;
-    map<s32, CharReach> look;
+    vector<LookProto> look;
 
     for (u32 lit_id : build.g[v].literals) {
         const rose_literal_id &lit = build.literals.at(lit_id);
         auto lit_look = findLiteralReach(lit);
 
         if (first) {
-            for (auto &p : lit_look) {
-                look.emplace(p.offset, p.reach);
-            }
+            look = std::move(lit_look);
             first = false;
             continue;
         }
@@ -512,22 +510,21 @@ map<s32, CharReach> findLiteralReach(const RoseBuildImpl &build,
                 look.erase(it, end(look));
                 break;
             }
-            if (it->first < jt->offset) {
+            if (it->offset < jt->offset) {
                 // Offset is present in look but not in lit_look, erase.
                 it = look.erase(it);
-            } else if (it->first > jt->offset) {
+            } else if (it->offset > jt->offset) {
                 // Offset is preset in lit_look but not in look, ignore.
                 ++jt;
             } else {
                 // Offset is present in both, union its reach with look.
-                it->second |= jt->reach;
+                it->reach |= jt->reach;
                 ++it;
                 ++jt;
             }
         }
     }
 
-    DEBUG_PRINTF("lit lookaround: %s\n", dump(look).c_str());
     return look;
 }
 
@@ -541,11 +538,11 @@ void trimLiterals(const RoseBuildImpl &build, const RoseVertex v,
     DEBUG_PRINTF("pre-trim lookaround: %s\n", dump(look).c_str());
 
     for (const auto &m : findLiteralReach(build, v)) {
-        auto it = look.find(m.first);
+        auto it = look.find(m.offset);
         if (it == end(look)) {
             continue;
         }
-        if (m.second.isSubsetOf(it->second)) {
+        if (m.reach.isSubsetOf(it->second)) {
             DEBUG_PRINTF("can trim entry at %d\n", it->first);
             look.erase(it);
         }