]> git.ipfire.org Git - thirdparty/vectorscan.git/commitdiff
ext param - more consistent depth check
authorMatthew Barr <matthew.barr@intel.com>
Tue, 14 Nov 2017 22:13:44 +0000 (09:13 +1100)
committerXiang Wang <xiang.w.wang@intel.com>
Fri, 19 Jan 2018 11:24:21 +0000 (06:24 -0500)
src/nfagraph/ng_extparam.cpp
src/nfagraph/ng_util.cpp
src/nfagraph/ng_util.h

index bc7f81efd9cf4c1f63ce0546dc21613577f85caa..6eb23113f38cbf1c579515f9caf68a5421f46097 100644 (file)
@@ -629,15 +629,6 @@ bool hasExtParams(const ExpressionInfo &expr) {
     return false;
 }
 
-template<class VertexDepth>
-depth maxDistFromStart(const VertexDepth &d) {
-    if (!d.fromStartDotStar.max.is_unreachable()) {
-        // A path from startDs, any path, implies we can match at any offset.
-        return depth::infinity();
-    }
-    return d.fromStart.max;
-}
-
 static
 const depth& maxDistToAccept(const NFAVertexBidiDepth &d) {
     if (d.toAccept.max.is_unreachable()) {
@@ -689,7 +680,7 @@ bool isEdgePrunable(const NGHolder &g, const Report &report,
     const NFAVertexBidiDepth &dv = depths.at(v_idx);
 
     if (report.minOffset) {
-        depth max_offset = maxDistFromStart(du) + maxDistToAccept(dv);
+        depth max_offset = maxDistFromStartOfData(du) + maxDistToAccept(dv);
         if (max_offset.is_finite() && max_offset < report.minOffset) {
             DEBUG_PRINTF("max_offset=%s too small\n", max_offset.str().c_str());
             return true;
@@ -709,7 +700,7 @@ bool isEdgePrunable(const NGHolder &g, const Report &report,
     if (report.minLength && is_any_accept(v, g)) {
         // Simple take on min_length. If we're an edge to accept and our max
         // dist from start is too small, we can be pruned.
-        const depth &width = du.fromStart.max;
+        const depth &width = maxDistFromInit(du);
         if (width.is_finite() && width < report.minLength) {
             DEBUG_PRINTF("max width %s from start too small for min_length\n",
                          width.str().c_str());
@@ -961,7 +952,7 @@ void removeUnneededOffsetBounds(NGHolder &g, ReportManager &rm) {
     replaceReports(g, [&](NFAVertex v, ReportID id) {
         const auto &d = depths.at(g[v].index);
         const depth &min_depth = min(d.fromStartDotStar.min, d.fromStart.min);
-        const depth &max_depth = maxDistFromStart(d);
+        const depth &max_depth = maxDistFromStartOfData(d);
 
         DEBUG_PRINTF("vertex %zu has min_depth=%s, max_depth=%s\n", g[v].index,
                      min_depth.str().c_str(), max_depth.str().c_str());
index 59c7349801ffe57b0bd8b44d58aa0f8c772b92da..cb2b7103582a827e3c4d236d37d3415475cdbf76 100644 (file)
@@ -32,7 +32,6 @@
 #include "ng_util.h"
 
 #include "grey.h"
-#include "ng_depth.h" // for NFAVertexDepth
 #include "ng_dump.h"
 #include "ng_prune.h"
 #include "ue2common.h"
@@ -61,25 +60,6 @@ using boost::make_assoc_property_map;
 
 namespace ue2 {
 
-depth maxDistFromInit(const NFAVertexDepth &vd) {
-    if (vd.fromStart.max.is_unreachable()) {
-        return vd.fromStartDotStar.max;
-    } else if (vd.fromStartDotStar.max.is_unreachable()) {
-        return vd.fromStart.max;
-    } else {
-        return max(vd.fromStartDotStar.max, vd.fromStart.max);
-    }
-}
-
-depth maxDistFromStartOfData(const NFAVertexDepth &vd) {
-    if (vd.fromStartDotStar.max.is_reachable()) {
-        /* the irrepressible nature of floating literals cannot be contained */
-        return depth::infinity();
-    } else {
-        return vd.fromStart.max;
-    }
-}
-
 NFAVertex getSoleDestVertex(const NGHolder &g, NFAVertex a) {
     assert(a != NGHolder::null_vertex());
 
index 3cc9c7c3edfba4216f4820f67dcdd7e96896108f..a2d0d9b7d6644afc86320e6726a43a40ee8d279a 100644 (file)
@@ -32,6 +32,7 @@
 #ifndef NG_UTIL_H
 #define NG_UTIL_H
 
+#include "ng_depth.h"
 #include "ng_holder.h"
 #include "ue2common.h"
 #include "util/flat_containers.h"
@@ -40,6 +41,7 @@
 
 #include <boost/graph/depth_first_search.hpp> // for default_dfs_visitor
 
+#include <algorithm>
 #include <map>
 #include <unordered_map>
 #include <vector>
 namespace ue2 {
 
 struct Grey;
-struct NFAVertexDepth;
 struct ue2_literal;
-class depth;
 class ReportManager;
 
-depth maxDistFromInit(const NFAVertexDepth &d);
-depth maxDistFromStartOfData(const NFAVertexDepth &d);
+template<class VertexDepth>
+depth maxDistFromInit(const VertexDepth &vd) {
+    if (vd.fromStart.max.is_unreachable()) {
+        return vd.fromStartDotStar.max;
+    } else if (vd.fromStartDotStar.max.is_unreachable()) {
+        return vd.fromStart.max;
+    } else {
+        return std::max(vd.fromStartDotStar.max, vd.fromStart.max);
+    }
+}
+
+template<class VertexDepth>
+depth maxDistFromStartOfData(const VertexDepth &vd) {
+    if (vd.fromStartDotStar.max.is_reachable()) {
+        /* the irrepressible nature of floating literals cannot be contained */
+        return depth::infinity();
+    } else {
+        return vd.fromStart.max;
+    }
+}
 
 /** True if the given vertex is a dot (reachable on any character). */
 template<class GraphT>