]> git.ipfire.org Git - thirdparty/vectorscan.git/commitdiff
ComponentRepeat: remove firsts_cache, precalc code
authorJustin Viiret <justin.viiret@intel.com>
Mon, 4 Jan 2016 04:33:05 +0000 (15:33 +1100)
committerMatthew Barr <matthew.barr@intel.com>
Tue, 1 Mar 2016 00:22:45 +0000 (11:22 +1100)
Firsts are easy to compute in ComponentRepeat::first() now.

src/parser/ComponentRepeat.cpp
src/parser/ComponentRepeat.h

index 670cee37e1d69b926f6b7d0708b3f8c36ffd19d9..ff02703cd288a8f1ceaaae9f2f67d5df2d567813 100644 (file)
@@ -87,8 +87,7 @@ ComponentRepeat::ComponentRepeat(const ComponentRepeat &other)
       type(other.type), sub_comp(unique_ptr<Component>(other.sub_comp->clone())),
       m_min(other.m_min), m_max(other.m_max),
       m_firsts(other.m_firsts), m_lasts(other.m_lasts),
-      posFirst(other.posFirst), posLast(other.posLast),
-      firsts_cache(other.firsts_cache) {}
+      posFirst(other.posFirst), posLast(other.posLast) {}
 
 bool ComponentRepeat::empty() const {
     return m_min == 0 || sub_comp->empty();
@@ -175,14 +174,24 @@ void ComponentRepeat::notePositions(GlushkovBuildState &bs) {
     }
 
     recordPosBounds(posFirst, bs.getBuilder().numVertices());
-    precalc_firsts(); /* ComponentRepeat requires firsts to be calculated ahead
-                       * of time and cached due to expense */
+
+    // Each optional repeat has an epsilon at the end of its firsts list.
+    for (u32 i = m_min; i < m_firsts.size(); i++) {
+        m_firsts[i].push_back(GlushkovBuildState::POS_EPSILON);
+    }
+
 }
 
 vector<PositionInfo> ComponentRepeat::first() const {
-    DEBUG_PRINTF("firsts = %s\n", dumpPositions(firsts_cache.begin(),
-                                                firsts_cache.end()).c_str());
-    return firsts_cache;
+    if (!m_max) {
+        return {};
+    }
+
+    assert(!m_firsts.empty()); // notePositions should already have run
+    const vector<PositionInfo> &firsts = m_firsts.front();
+    DEBUG_PRINTF("firsts = %s\n",
+                 dumpPositions(begin(firsts), end(firsts)).c_str());
+    return firsts;
 }
 
 void ComponentRepeat::buildFollowSet(GlushkovBuildState &bs,
@@ -331,27 +340,6 @@ inf_check:
     }
 }
 
-void ComponentRepeat::precalc_firsts() {
-    DEBUG_PRINTF("building firsts for {%u,%u} repeat with %s sub\n", m_min,
-                 m_max, sub_comp->empty() ? "emptiable" : "non-emptiable");
-
-    /* For normal repeat, our optional repeats each have an epsilon at the end
-     * of their firsts lists.
-     */
-    for (u32 i = m_min; i < m_firsts.size(); i++) {
-        m_firsts[i].push_back(GlushkovBuildState::POS_EPSILON);
-    }
-
-    firsts_cache.clear();
-    if (!m_max) {
-        return;
-    }
-
-    assert(!m_firsts.empty()); // notePositions should already have run
-    const vector<PositionInfo> &f = m_firsts.front();
-    firsts_cache.insert(firsts_cache.end(), f.begin(), f.end());
-}
-
 static
 bool hasPositionFlags(const Component &c) {
     for (const auto &e : c.first()) {
index b708e062e296bf135efdd96d796aba49edeef29c..8905bfcf5efc5c9818fd2abf97c31a6f35251d81 100644 (file)
@@ -120,8 +120,6 @@ public:
     enum RepeatType type;
 
 protected:
-    /** Called by \ref buildFollowSet to connect up the various repeats. */
-    void precalc_firsts();
     void postSubNotePositionHook();
     void wireRepeats(GlushkovBuildState &bs);
 
@@ -134,8 +132,6 @@ protected:
     Position posFirst;
     Position posLast;
 
-    std::vector<PositionInfo> firsts_cache;
-
     ComponentRepeat(const ComponentRepeat &other);
 };