diff --git a/src/nfagraph/ng_extparam.cpp b/src/nfagraph/ng_extparam.cpp index bc7f81ef..6eb23113 100644 --- a/src/nfagraph/ng_extparam.cpp +++ b/src/nfagraph/ng_extparam.cpp @@ -629,15 +629,6 @@ bool hasExtParams(const ExpressionInfo &expr) { return false; } -template -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()); diff --git a/src/nfagraph/ng_util.cpp b/src/nfagraph/ng_util.cpp index 59c73498..cb2b7103 100644 --- a/src/nfagraph/ng_util.cpp +++ b/src/nfagraph/ng_util.cpp @@ -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()); diff --git a/src/nfagraph/ng_util.h b/src/nfagraph/ng_util.h index 3cc9c7c3..a2d0d9b7 100644 --- a/src/nfagraph/ng_util.h +++ b/src/nfagraph/ng_util.h @@ -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 // for default_dfs_visitor +#include #include #include #include @@ -47,13 +49,29 @@ namespace ue2 { struct Grey; -struct NFAVertexDepth; struct ue2_literal; -class depth; class ReportManager; -depth maxDistFromInit(const NFAVertexDepth &d); -depth maxDistFromStartOfData(const NFAVertexDepth &d); +template +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 +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