]> git.ipfire.org Git - thirdparty/vectorscan.git/commitdiff
rose_build_anchored: clean up remapping
authorJustin Viiret <justin.viiret@intel.com>
Thu, 14 Jul 2016 03:34:56 +0000 (13:34 +1000)
committerMatthew Barr <matthew.barr@intel.com>
Wed, 10 Aug 2016 04:59:10 +0000 (14:59 +1000)
Note that there are no EOD reports in the anchored matcher raw_dfas.

src/rose/rose_build_anchored.cpp

index befd0bad6e0133da49af83251ad5c2acc9b0a9ea..60732ff9105fc63d709a8267777b5bbeb8e65cd0 100644 (file)
@@ -173,47 +173,36 @@ void mergeAnchoredDfas(vector<unique_ptr<raw_dfa>> &dfas,
 }
 
 static
-void translateReportSet(flat_set<ReportID> *rset, const RoseBuildImpl &tbi) {
-    flat_set<ReportID> old;
-    old.swap(*rset);
-    for (auto report_id : old) {
-        DEBUG_PRINTF("updating %u -> %u\n", report_id,
-                     tbi.literal_info[report_id].final_id);
-        rset->insert(tbi.literal_info[report_id].final_id);
-    }
-}
+void remapAnchoredReports(raw_dfa &rdfa, const RoseBuildImpl &build) {
+    for (dstate &ds : rdfa.states) {
+        assert(ds.reports_eod.empty()); // Not used in anchored matcher.
+        if (ds.reports.empty()) {
+            continue;
+        }
 
-static
-void remapAnchoredReports(raw_dfa &dfa, const RoseBuildImpl &tbi) {
-    for (dstate &ds : dfa.states) {
-        translateReportSet(&ds.reports, tbi);
-        translateReportSet(&ds.reports_eod, tbi);
+        flat_set<ReportID> new_reports;
+        for (auto id : ds.reports) {
+            assert(id < build.literal_info.size());
+            new_reports.insert(build.literal_info.at(id).final_id);
+        }
+        ds.reports = move(new_reports);
     }
 }
 
-/* Replaces the report ids currently in the dfas (rose graph literal ids) with
- * the final id used by the runtime. */
+/**
+ * \brief Replaces the report ids currently in the dfas (rose graph literal
+ * ids) with the final id for each literal.
+ */
 static
-void remapAnchoredReports(RoseBuildImpl &tbi) {
-    for (auto it = tbi.anchored_nfas.begin(); it != tbi.anchored_nfas.end();
-         ++it) {
-        for (auto &rdfa : it->second) {
+void remapAnchoredReports(RoseBuildImpl &build) {
+    for (auto &m : build.anchored_nfas) {
+        for (auto &rdfa : m.second) {
             assert(rdfa);
-            remapAnchoredReports(*rdfa, tbi);
+            remapAnchoredReports(*rdfa, build);
         }
     }
 }
 
-static
-void remapIds(flat_set<ReportID> &reports, const vector<u32> &litPrograms) {
-    flat_set<ReportID> new_reports;
-    for (auto id : reports) {
-        assert(id < litPrograms.size());
-        new_reports.insert(litPrograms.at(id));
-    }
-    reports = move(new_reports);
-}
-
 /**
  * \brief Replace the reports (which are literal final_ids) in the given
  * raw_dfa with program offsets.
@@ -221,8 +210,17 @@ void remapIds(flat_set<ReportID> &reports, const vector<u32> &litPrograms) {
 static
 void remapIdsToPrograms(raw_dfa &rdfa, const vector<u32> &litPrograms) {
     for (dstate &ds : rdfa.states) {
-        remapIds(ds.reports, litPrograms);
-        remapIds(ds.reports_eod, litPrograms);
+        assert(ds.reports_eod.empty()); // Not used in anchored matcher.
+        if (ds.reports.empty()) {
+            continue;
+        }
+
+        flat_set<ReportID> new_reports;
+        for (auto id : ds.reports) {
+            assert(id < litPrograms.size());
+            new_reports.insert(litPrograms.at(id));
+        }
+        ds.reports = move(new_reports);
     }
 }