Remove "dot" entries from leftfix lookarounds

Note that we have to be careful to leave the first lookaround entry in
place, if it's a dot. This should eventually be done with a program
instruction.
This commit is contained in:
Justin Viiret 2016-01-06 11:45:31 +11:00 committed by Matthew Barr
parent e92a20e5fa
commit e051077a26

View File

@ -582,6 +582,30 @@ bool getTransientPrefixReach(const NGHolder &g, u32 lag,
return true;
}
static
void normaliseLeftfix(map<s32, CharReach> &look) {
// We can erase entries where the reach is "all characters", except for the
// very first one -- this might be required to establish a minimum bound on
// the literal's match offset.
// TODO: It would be cleaner to use a literal program instruction to check
// the minimum bound explicitly.
if (look.empty()) {
return;
}
const auto earliest = begin(look)->first;
vector<s32> dead;
for (const auto &m : look) {
if (m.second.all() && m.first != earliest) {
dead.push_back(m.first);
}
}
erase_all(&look, dead);
}
bool makeLeftfixLookaround(const RoseBuildImpl &build, const RoseVertex v,
vector<LookEntry> &lookaround) {
lookaround.clear();
@ -606,6 +630,7 @@ bool makeLeftfixLookaround(const RoseBuildImpl &build, const RoseVertex v,
}
trimLiterals(build, v, look);
normaliseLeftfix(look);
if (look.size() > MAX_LOOKAROUND_ENTRIES) {
DEBUG_PRINTF("lookaround too big (%zu entries)\n", look.size());