phase 1 of addressing cppcheck useStlAlgorithm warnings,

this set only includes fill and copy operations.
This commit is contained in:
G.E
2024-05-14 17:37:38 +03:00
parent 5ebc19674c
commit b541288cd5
19 changed files with 102 additions and 98 deletions

View File

@@ -92,11 +92,12 @@ static const CharReach CHARREACH_NONWORD_UCP_PRE(CHARREACH_NONWORD);
static
vector<NFAEdge> getAsserts(const NGHolder &g) {
vector<NFAEdge> out;
for (const auto &e : edges_range(g)) {
if (g[e].assert_flags) {
out.emplace_back(e);
}
}
auto assertflags = [&g=g](const NFAEdge &e) {
return (g[e].assert_flags);
};
const auto &er = edges_range(g);
std::copy_if(begin(er), end(er), std::back_inserter(out), assertflags);
return out;
}

View File

@@ -512,17 +512,17 @@ bool removeSiblingsOfStartDotStar(NGHolder &g) {
* for SOM mode. (see UE-1544) */
bool optimiseVirtualStarts(NGHolder &g) {
vector<NFAEdge> dead;
auto deads = [&g=g](const NFAEdge &e) {
return (!is_any_start(source(e, g), g));
};
for (auto v : adjacent_vertices_range(g.startDs, g)) {
u32 flags = g[v].assert_flags;
if (!(flags & POS_FLAG_VIRTUAL_START)) {
continue;
}
for (const auto &e : in_edges_range(v, g)) {
if (!is_any_start(source(e, g), g)) {
dead.emplace_back(e);
}
}
const auto &e = in_edges_range(v, g);
std::copy_if(begin(e), end(e), std::back_inserter(dead), deads);
}
if (dead.empty()) {

View File

@@ -571,6 +571,9 @@ bool transformMinLengthToRepeat(NGHolder &g, ReportManager &rm) {
vector<NFAVertex> preds;
vector<NFAEdge> dead;
auto deads = [&g=g](const NFAEdge &e) {
return (target(e, g) != g.startDs);
};
for (auto u : inv_adjacent_vertices_range(cyclic, g)) {
DEBUG_PRINTF("pred %zu\n", g[u].index);
if (u == cyclic) {
@@ -580,11 +583,9 @@ bool transformMinLengthToRepeat(NGHolder &g, ReportManager &rm) {
// We want to delete the out-edges of each predecessor, but need to
// make sure we don't delete the startDs self loop.
for (const auto &e : out_edges_range(u, g)) {
if (target(e, g) != g.startDs) {
dead.emplace_back(e);
}
}
const auto &e = out_edges_range(u, g);
std::copy_if(begin(e), end(e), std::back_inserter(dead), deads);
}
remove_edges(dead, g);

View File

@@ -389,11 +389,11 @@ void reusePredsAsStarts(const NGHolder &g, const map<u32, CharReach> &top_reach,
/* create list of candidates first, to avoid issues of iter invalidation */
DEBUG_PRINTF("attempting to reuse vertices for top starts\n");
vector<NFAVertex> cand_starts;
for (NFAVertex u : unhandled_succ_tops | map_keys) {
if (hasSelfLoop(u, g)) {
cand_starts.emplace_back(u);
}
}
auto cands = [&g=g](const NFAVertex &u) {
return (hasSelfLoop(u, g));
};
const auto &u = unhandled_succ_tops | map_keys;
std::copy_if(begin(u), end(u), std::back_inserter(cand_starts), cands);
for (NFAVertex u : cand_starts) {
if (!contains(unhandled_succ_tops, u)) {

View File

@@ -488,9 +488,9 @@ vector<LitEdge> add_reverse_edges_and_index(LitGraph &lg) {
const size_t edge_count = num_edges(lg);
vector<LitEdge> fwd_edges;
fwd_edges.reserve(edge_count);
for (const auto &e : edges_range(lg)) {
fwd_edges.push_back(e);
}
const auto &e = edges_range(lg);
std::copy(begin(e), end(e), std::back_inserter(fwd_edges));
vector<LitEdge> rev_map(2 * edge_count);

View File

@@ -62,11 +62,13 @@ void pruneUnreachable(NGHolder &g) {
&& edge(g.accept, g.acceptEod, g).second) {
// Trivial case: there are no in-edges to our accepts (other than
// accept->acceptEod), so all non-specials are unreachable.
for (auto v : vertices_range(g)) {
if (!is_special(v, g)) {
dead.emplace_back(v);
}
}
auto deads = [&g=g](const NFAVertex &v) {
return (!is_special(v, g));
};
const auto &vr = vertices_range(g);
std::copy_if(begin(vr), end(vr), std::back_inserter(dead), deads);
} else {
// Walk a reverse graph from acceptEod with Boost's depth_first_visit
// call.
@@ -199,17 +201,17 @@ void pruneHighlanderAccepts(NGHolder &g, const ReportManager &rm) {
}
vector<NFAEdge> dead;
auto deads = [&g=g](const NFAEdge &e) {
return (!is_any_accept(target(e, g), g));
};
for (auto u : inv_adjacent_vertices_range(g.accept, g)) {
if (is_special(u, g)) {
continue;
}
// We can prune any out-edges that aren't accepts
for (const auto &e : out_edges_range(u, g)) {
if (!is_any_accept(target(e, g), g)) {
dead.emplace_back(e);
}
}
const auto &er = out_edges_range(u, g);
std::copy_if(begin(er), end(er), std::back_inserter(dead), deads);
}
if (dead.empty()) {

View File

@@ -58,11 +58,12 @@ vector<DepthMinMax> getDistancesFromSOM(const NGHolder &g_orig) {
cloneHolder(g, g_orig, &vmap);
vector<NFAVertex> vstarts;
for (auto v : vertices_range(g)) {
if (is_virtual_start(v, g)) {
vstarts.emplace_back(v);
}
}
auto vstart = [&g=g](const NFAVertex &v) {
return (is_virtual_start(v, g));
};
const auto &vr = vertices_range(g);
std::copy_if(begin(vr), end(vr), std::back_inserter(vstarts), vstart);
vstarts.emplace_back(g.startDs);
// wire the successors of every virtual start or startDs to g.start.

View File

@@ -405,9 +405,10 @@ void appendLiteral(NGHolder &h, const ue2_literal &s) {
DEBUG_PRINTF("adding '%s' to graph\n", dumpString(s).c_str());
vector<NFAVertex> tail;
assert(in_degree(h.acceptEod, h) == 1);
for (auto v : inv_adjacent_vertices_range(h.accept, h)) {
tail.emplace_back(v);
}
const auto &vr = inv_adjacent_vertices_range(h.accept, h);
std::copy(begin(vr), end(vr), std::back_inserter(tail));
assert(!tail.empty());
for (auto v : tail) {