mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-06-28 16:41:01 +03:00
ComponentRepeat: remove firsts_cache, precalc code
Firsts are easy to compute in ComponentRepeat::first() now.
This commit is contained in:
parent
3d049d6de3
commit
e92a20e5fa
@ -87,8 +87,7 @@ ComponentRepeat::ComponentRepeat(const ComponentRepeat &other)
|
|||||||
type(other.type), sub_comp(unique_ptr<Component>(other.sub_comp->clone())),
|
type(other.type), sub_comp(unique_ptr<Component>(other.sub_comp->clone())),
|
||||||
m_min(other.m_min), m_max(other.m_max),
|
m_min(other.m_min), m_max(other.m_max),
|
||||||
m_firsts(other.m_firsts), m_lasts(other.m_lasts),
|
m_firsts(other.m_firsts), m_lasts(other.m_lasts),
|
||||||
posFirst(other.posFirst), posLast(other.posLast),
|
posFirst(other.posFirst), posLast(other.posLast) {}
|
||||||
firsts_cache(other.firsts_cache) {}
|
|
||||||
|
|
||||||
bool ComponentRepeat::empty() const {
|
bool ComponentRepeat::empty() const {
|
||||||
return m_min == 0 || sub_comp->empty();
|
return m_min == 0 || sub_comp->empty();
|
||||||
@ -175,14 +174,24 @@ void ComponentRepeat::notePositions(GlushkovBuildState &bs) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
recordPosBounds(posFirst, bs.getBuilder().numVertices());
|
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 {
|
vector<PositionInfo> ComponentRepeat::first() const {
|
||||||
DEBUG_PRINTF("firsts = %s\n", dumpPositions(firsts_cache.begin(),
|
if (!m_max) {
|
||||||
firsts_cache.end()).c_str());
|
return {};
|
||||||
return firsts_cache;
|
}
|
||||||
|
|
||||||
|
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,
|
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
|
static
|
||||||
bool hasPositionFlags(const Component &c) {
|
bool hasPositionFlags(const Component &c) {
|
||||||
for (const auto &e : c.first()) {
|
for (const auto &e : c.first()) {
|
||||||
|
@ -120,8 +120,6 @@ public:
|
|||||||
enum RepeatType type;
|
enum RepeatType type;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/** Called by \ref buildFollowSet to connect up the various repeats. */
|
|
||||||
void precalc_firsts();
|
|
||||||
void postSubNotePositionHook();
|
void postSubNotePositionHook();
|
||||||
void wireRepeats(GlushkovBuildState &bs);
|
void wireRepeats(GlushkovBuildState &bs);
|
||||||
|
|
||||||
@ -134,8 +132,6 @@ protected:
|
|||||||
Position posFirst;
|
Position posFirst;
|
||||||
Position posLast;
|
Position posLast;
|
||||||
|
|
||||||
std::vector<PositionInfo> firsts_cache;
|
|
||||||
|
|
||||||
ComponentRepeat(const ComponentRepeat &other);
|
ComponentRepeat(const ComponentRepeat &other);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user