mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-07-14 06:24:43 +03:00
rose_build_lookaround: use vector in trimLiterals
This commit is contained in:
parent
4889a492e4
commit
1f2eb5a093
@ -485,19 +485,17 @@ vector<LookProto> findLiteralReach(const rose_literal_id &lit) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
map<s32, CharReach> findLiteralReach(const RoseBuildImpl &build,
|
vector<LookProto> findLiteralReach(const RoseBuildImpl &build,
|
||||||
const RoseVertex v) {
|
const RoseVertex v) {
|
||||||
bool first = true;
|
bool first = true;
|
||||||
map<s32, CharReach> look;
|
vector<LookProto> look;
|
||||||
|
|
||||||
for (u32 lit_id : build.g[v].literals) {
|
for (u32 lit_id : build.g[v].literals) {
|
||||||
const rose_literal_id &lit = build.literals.at(lit_id);
|
const rose_literal_id &lit = build.literals.at(lit_id);
|
||||||
auto lit_look = findLiteralReach(lit);
|
auto lit_look = findLiteralReach(lit);
|
||||||
|
|
||||||
if (first) {
|
if (first) {
|
||||||
for (auto &p : lit_look) {
|
look = std::move(lit_look);
|
||||||
look.emplace(p.offset, p.reach);
|
|
||||||
}
|
|
||||||
first = false;
|
first = false;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -512,22 +510,21 @@ map<s32, CharReach> findLiteralReach(const RoseBuildImpl &build,
|
|||||||
look.erase(it, end(look));
|
look.erase(it, end(look));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (it->first < jt->offset) {
|
if (it->offset < jt->offset) {
|
||||||
// Offset is present in look but not in lit_look, erase.
|
// Offset is present in look but not in lit_look, erase.
|
||||||
it = look.erase(it);
|
it = look.erase(it);
|
||||||
} else if (it->first > jt->offset) {
|
} else if (it->offset > jt->offset) {
|
||||||
// Offset is preset in lit_look but not in look, ignore.
|
// Offset is preset in lit_look but not in look, ignore.
|
||||||
++jt;
|
++jt;
|
||||||
} else {
|
} else {
|
||||||
// Offset is present in both, union its reach with look.
|
// Offset is present in both, union its reach with look.
|
||||||
it->second |= jt->reach;
|
it->reach |= jt->reach;
|
||||||
++it;
|
++it;
|
||||||
++jt;
|
++jt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DEBUG_PRINTF("lit lookaround: %s\n", dump(look).c_str());
|
|
||||||
return look;
|
return look;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -541,11 +538,11 @@ void trimLiterals(const RoseBuildImpl &build, const RoseVertex v,
|
|||||||
DEBUG_PRINTF("pre-trim lookaround: %s\n", dump(look).c_str());
|
DEBUG_PRINTF("pre-trim lookaround: %s\n", dump(look).c_str());
|
||||||
|
|
||||||
for (const auto &m : findLiteralReach(build, v)) {
|
for (const auto &m : findLiteralReach(build, v)) {
|
||||||
auto it = look.find(m.first);
|
auto it = look.find(m.offset);
|
||||||
if (it == end(look)) {
|
if (it == end(look)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (m.second.isSubsetOf(it->second)) {
|
if (m.reach.isSubsetOf(it->second)) {
|
||||||
DEBUG_PRINTF("can trim entry at %d\n", it->first);
|
DEBUG_PRINTF("can trim entry at %d\n", it->first);
|
||||||
look.erase(it);
|
look.erase(it);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user