replace push_back by emplace_back where possible

This commit is contained in:
Konstantinos Margaritis
2021-03-26 12:39:40 +02:00
parent 9f7088a9e0
commit 556206f138
92 changed files with 535 additions and 535 deletions

View File

@@ -105,7 +105,7 @@ static
path append(const path &orig, const CharReach &cr, u32 new_dest) {
path p(new_dest);
p.reach = orig.reach;
p.reach.push_back(cr);
p.reach.emplace_back(cr);
return p;
}
@@ -117,25 +117,25 @@ void extend(const raw_dfa &rdfa, const vector<CharReach> &rev_map,
const dstate &s = rdfa.states[p.dest];
if (!p.reach.empty() && p.reach.back().none()) {
out.push_back(p);
out.emplace_back(p);
return;
}
if (!s.reports.empty()) {
if (generates_callbacks(rdfa.kind)) {
out.push_back(p);
out.emplace_back(p);
return;
} else {
path pp = append(p, CharReach(), p.dest);
all[p.dest].push_back(pp);
out.push_back(move(pp));
all[p.dest].emplace_back(pp);
out.emplace_back(move(pp));
}
}
if (!s.reports_eod.empty()) {
path pp = append(p, CharReach(), p.dest);
all[p.dest].push_back(pp);
out.push_back(move(pp));
all[p.dest].emplace_back(pp);
out.emplace_back(move(pp));
}
flat_map<u32, CharReach> dest;
@@ -154,8 +154,8 @@ void extend(const raw_dfa &rdfa, const vector<CharReach> &rev_map,
DEBUG_PRINTF("----good: [%s] -> %u\n",
describeClasses(pp.reach).c_str(), pp.dest);
all[e.first].push_back(pp);
out.push_back(move(pp));
all[e.first].emplace_back(pp);
out.emplace_back(move(pp));
}
}
@@ -165,7 +165,7 @@ vector<vector<CharReach>> generate_paths(const raw_dfa &rdfa,
const vector<CharReach> rev_map = reverse_alpha_remapping(rdfa);
vector<path> paths{path(base)};
unordered_map<u32, vector<path>> all;
all[base].push_back(path(base));
all[base].emplace_back(path(base));
for (u32 i = 0; i < len && paths.size() < PATHS_LIMIT; i++) {
vector<path> next_gen;
for (const auto &p : paths) {
@@ -180,7 +180,7 @@ vector<vector<CharReach>> generate_paths(const raw_dfa &rdfa,
vector<vector<CharReach>> rv;
rv.reserve(paths.size());
for (auto &p : paths) {
rv.push_back(vector<CharReach>(std::make_move_iterator(p.reach.begin()),
rv.emplace_back(vector<CharReach>(std::make_move_iterator(p.reach.begin()),
std::make_move_iterator(p.reach.end())));
}
return rv;
@@ -318,7 +318,7 @@ set<dstate_id_t> find_region(const raw_dfa &rdfa, dstate_id_t base,
DEBUG_PRINTF(" %hu is in region\n", t);
region.insert(t);
pending.push_back(t);
pending.emplace_back(t);
}
}

View File

@@ -157,7 +157,7 @@ void getNeighborInfo(const CliqueGraph &g, vector<u32> &neighbor,
// find neighbors for cv
for (const auto &v : adjacent_vertices_range(cv, g)) {
if (g[v].stateId != id && contains(group, g[v].stateId)) {
neighbor.push_back(g[v].stateId);
neighbor.emplace_back(g[v].stateId);
DEBUG_PRINTF("Neighbor:%u\n", g[v].stateId);
}
}
@@ -172,7 +172,7 @@ void findCliqueGroup(CliqueGraph &cg, vector<u32> &clique) {
vector<u32> init;
for (const auto &v : vertices_range(cg)) {
vertexMap[cg[v].stateId] = v;
init.push_back(cg[v].stateId);
init.emplace_back(cg[v].stateId);
}
gStack.push(init);
@@ -186,7 +186,7 @@ void findCliqueGroup(CliqueGraph &cg, vector<u32> &clique) {
// Choose a vertex from the graph
u32 id = g[0];
const CliqueVertex &n = vertexMap.at(id);
clique.push_back(id);
clique.emplace_back(id);
// Corresponding vertex in the original graph
vector<u32> neighbor;
set<u32> subgraphId(g.begin(), g.end());
@@ -215,7 +215,7 @@ vector<u32> removeClique(CliqueGraph &cg) {
vector<CliqueVertex> dead;
for (const auto &v : vertices_range(cg)) {
if (find(c.begin(), c.end(), cg[v].stateId) != c.end()) {
dead.push_back(v);
dead.emplace_back(v);
}
}
for (const auto &v : dead) {
@@ -227,7 +227,7 @@ vector<u32> removeClique(CliqueGraph &cg) {
}
vector<u32> clique;
findCliqueGroup(cg, clique);
cliquesVec.push_back(clique);
cliquesVec.emplace_back(clique);
}
// get the independent set with max size
@@ -288,11 +288,11 @@ vector<vector<u32>> checkExclusion(u32 &streamStateSize,
// get min reset distance for each repeat
for (size_t i = lower; i < upper; i++) {
CliqueVertex v = add_vertex(CliqueVertexProps(i), *cg);
vertices.push_back(v);
vertices.emplace_back(v);
const vector<size_t> &tmp_dist =
minResetDistToEnd(triggers[i], cr);
min_reset_dist.push_back(tmp_dist);
min_reset_dist.emplace_back(tmp_dist);
}
// find exclusive pair for each repeat
@@ -311,7 +311,7 @@ vector<vector<u32>> checkExclusion(u32 &streamStateSize,
auto clique = removeClique(*cg);
size_t cliqueSize = clique.size();
if (cliqueSize > 1) {
groups.push_back(clique);
groups.emplace_back(clique);
exclusive = EXCLUSIVE;
total += cliqueSize;
}
@@ -387,7 +387,7 @@ void buildSubcastles(const CastleProto &proto, vector<SubCastle> &subs,
}
if (pr.bounds.max.is_finite()) {
may_stale.push_back(i);
may_stale.emplace_back(i);
}
info.type = verify_u8(rtype);
@@ -411,7 +411,7 @@ void buildSubcastles(const CastleProto &proto, vector<SubCastle> &subs,
if (rtype == REPEAT_SPARSE_OPTIMAL_P) {
for (u32 j = 0; j < rsi.patchSize; j++) {
tables.push_back(rsi.table[j]);
tables.emplace_back(rsi.table[j]);
}
sparseRepeats++;
patchSize[i] = rsi.patchSize;
@@ -509,10 +509,10 @@ buildCastle(const CastleProto &proto,
is_reset = true;
}
repeatInfoPair.push_back(make_pair(min_period, is_reset));
repeatInfoPair.emplace_back(make_pair(min_period, is_reset));
candidateTriggers.push_back(triggers.at(top));
candidateRepeats.push_back(i);
candidateTriggers.emplace_back(triggers.at(top));
candidateRepeats.emplace_back(i);
}
// Case 1: exclusive repeats

View File

@@ -152,7 +152,7 @@ HopcroftInfo::HopcroftInfo(const raw_dfa &rdfa)
for (size_t i = 0; i < states.size(); i++) { // i is the previous state
for (size_t sym = 0; sym < alpha_size; sym++) {
dstate_id_t present_state = rdfa.states[i].next[sym];
states[present_state].prev[sym].push_back(i);
states[present_state].prev[sym].emplace_back(i);
}
}
}
@@ -263,7 +263,7 @@ void mapping_new_states(const HopcroftInfo &info,
new_states.reserve(num_partitions);
for (const auto &m : ordering) {
new_states.push_back(rdfa.states[m.first]);
new_states.emplace_back(rdfa.states[m.first]);
}
rdfa.states = std::move(new_states);
}

View File

@@ -147,7 +147,7 @@ void translateRawReports(UNUSED GoughGraph &cfg, UNUSED const raw_som_dfa &raw,
} else {
var = joins_at_s.at(sr.slot);
}
reports_out->push_back(make_pair(sr.report, var));
reports_out->emplace_back(make_pair(sr.report, var));
}
}
@@ -190,7 +190,7 @@ void makeCFG_top_edge(GoughGraph &cfg, const vector<GoughVertex> &vertices,
shared_ptr<GoughSSAVarNew> vnew;
if (slot_id == trigger_slot) {
vnew = make_shared<GoughSSAVarNew>(0U);
cfg[e].vars.push_back(vnew);
cfg[e].vars.emplace_back(vnew);
} else {
assert(contains(src_slots, slot_id));
}
@@ -207,7 +207,7 @@ void makeCFG_top_edge(GoughGraph &cfg, const vector<GoughVertex> &vertices,
assert(contains(src_slots, slot_id));
shared_ptr<GoughSSAVarMin> vmin = make_shared<GoughSSAVarMin>();
cfg[e].vars.push_back(vmin);
cfg[e].vars.emplace_back(vmin);
final_var = vmin.get();
DEBUG_PRINTF("slot %u gets a new value\n", slot_id);
@@ -280,7 +280,7 @@ void makeCFG_edge(GoughGraph &cfg, const map<u32, u32> &som_creators,
vnew = vnew_by_adj[adjust];
} else {
vnew = make_shared<GoughSSAVarNew>(adjust);
cfg[e].vars.push_back(vnew);
cfg[e].vars.emplace_back(vnew);
vnew_by_adj[adjust] = vnew;
}
assert(vnew);
@@ -318,7 +318,7 @@ void makeCFG_edge(GoughGraph &cfg, const map<u32, u32> &som_creators,
DEBUG_PRINTF("bypassing min on join %u\n", slot_id);
} else {
shared_ptr<GoughSSAVarMin> vmin = make_shared<GoughSSAVarMin>();
cfg[e].vars.push_back(vmin);
cfg[e].vars.emplace_back(vmin);
final_var = vmin.get();
if (vnew) {
@@ -352,13 +352,13 @@ unique_ptr<GoughGraph> makeCFG(const raw_som_dfa &raw) {
u32 min_state = !is_triggered(raw.kind);
if (min_state) {
vertices.push_back(GoughGraph::null_vertex()); /* skip dead state */
vertices.emplace_back(GoughGraph::null_vertex()); /* skip dead state */
}
vector<flat_map<u32, GoughSSAVarJoin *> > joins(raw.states.size());
for (u32 i = min_state; i < raw.states.size(); ++i) {
GoughVertex v = add_vertex(GoughVertexProps(i), *cfg);
vertices.push_back(v);
vertices.emplace_back(v);
/* create JOIN variables */
for (som_tran_info::const_iterator it = raw.state_som[i].preds.begin();
@@ -366,7 +366,7 @@ unique_ptr<GoughGraph> makeCFG(const raw_som_dfa &raw) {
u32 slot_id = it->first;
if (!contains(raw.new_som_nfa_states, slot_id)
|| raw.new_som_nfa_states.at(slot_id)) {
(*cfg)[v].vars.push_back(make_shared<GoughSSAVarJoin>());
(*cfg)[v].vars.emplace_back(make_shared<GoughSSAVarJoin>());
joins[get(vertex_index, *cfg, v)][slot_id]
= (*cfg)[v].vars.back().get();
DEBUG_PRINTF("dfa %u:: slot %u\n", i, slot_id);
@@ -525,7 +525,7 @@ void mark_live_reports(const vector<pair<ReportID, GoughSSAVar *> > &reps,
continue;
}
var->seen = true;
queue->push_back(var);
queue->emplace_back(var);
}
}
@@ -546,7 +546,7 @@ void remove_dead(GoughGraph &g) {
continue;
}
var->seen = true;
queue.push_back(var);
queue.emplace_back(var);
}
}
@@ -589,7 +589,7 @@ gough_ins make_gough_ins(u8 op, u32 dest = INVALID_SLOT,
void GoughSSAVarNew::generate(vector<gough_ins> *out) const {
assert(slot != INVALID_SLOT);
out->push_back(make_gough_ins(GOUGH_INS_NEW, slot, adjust));
out->emplace_back(make_gough_ins(GOUGH_INS_NEW, slot, adjust));
}
#ifndef NDEBUG
@@ -616,7 +616,7 @@ void GoughSSAVarMin::generate(vector<gough_ins> *out) const {
/* if the destination is one of the sources, no need to move it */
first = false;
} else {
input_slots.push_back(var->slot);
input_slots.emplace_back(var->slot);
}
}
@@ -624,10 +624,10 @@ void GoughSSAVarMin::generate(vector<gough_ins> *out) const {
for (const u32 &input_slot : input_slots) {
if (first) {
out->push_back(make_gough_ins(GOUGH_INS_MOV, slot, input_slot));
out->emplace_back(make_gough_ins(GOUGH_INS_MOV, slot, input_slot));
first = false;
} else {
out->push_back(make_gough_ins(GOUGH_INS_MIN, slot, input_slot));
out->emplace_back(make_gough_ins(GOUGH_INS_MIN, slot, input_slot));
}
}
}
@@ -842,7 +842,7 @@ void add_simple_joins(edge_join_info &eji, vector<gough_ins> *out) {
/* value of destination slot is not used by any remaining joins;
* we can output this join immediately */
DEBUG_PRINTF("out %u<-%u\n", dest, src);
out->push_back(make_gough_ins(GOUGH_INS_MOV, dest, src));
out->emplace_back(make_gough_ins(GOUGH_INS_MOV, dest, src));
eji.erase(src, dest);
@@ -877,14 +877,14 @@ void add_joins_to_block(edge_join_info &eji, vector<gough_ins> *out,
/* stash the initial value of the split register in a temp register */
u32 temp = base_temp_slot++;
DEBUG_PRINTF("out %u<-%u\n", temp, split);
out->push_back(make_gough_ins(GOUGH_INS_MOV, temp, split));
out->emplace_back(make_gough_ins(GOUGH_INS_MOV, temp, split));
eji.remap_src(split, temp); /* update maps */
/* split can now be safely written out to as all the uses of it as an
* input now refer to temp instead */
DEBUG_PRINTF("out %u<-%u\n", split, input_for_split);
out->push_back(make_gough_ins(GOUGH_INS_MOV, split, input_for_split));
out->emplace_back(make_gough_ins(GOUGH_INS_MOV, split, input_for_split));
eji.erase(input_for_split, split);
/* handle any uncovered simple cases */
@@ -931,7 +931,7 @@ void build_blocks(const GoughGraph &g,
for (vector<gough_ins> &ins_list : *blocks | map_values) {
assert(!ins_list.empty());
ins_list.push_back(make_gough_ins(GOUGH_INS_END));
ins_list.emplace_back(make_gough_ins(GOUGH_INS_END));
}
}
@@ -1252,39 +1252,39 @@ unique_ptr<raw_report_info> gough_build_strat::gatherReports(
DEBUG_PRINTF("i = %zu [%zu]\n", reports.size(), gg[v].reports.size());
if (v == GoughGraph::null_vertex() || gg[v].reports.empty()) {
reports.push_back(MO_INVALID_IDX);
reports.emplace_back(MO_INVALID_IDX);
continue;
}
raw_gough_report_list rrl(gg[v].reports, rm, remap_reports);
DEBUG_PRINTF("non empty r %zu\n", reports.size());
if (rev.find(rrl) != rev.end()) {
reports.push_back(rev[rrl]);
reports.emplace_back(rev[rrl]);
} else {
DEBUG_PRINTF("adding to rl\n");
rev[rrl] = ri->size();
reports.push_back(ri->size());
ri->rl.push_back(rrl);
reports.emplace_back(ri->size());
ri->rl.emplace_back(rrl);
}
}
for (auto v : verts) {
if (v == GoughGraph::null_vertex() || gg[v].reports_eod.empty()) {
reports_eod.push_back(MO_INVALID_IDX);
reports_eod.emplace_back(MO_INVALID_IDX);
continue;
}
DEBUG_PRINTF("non empty r eod\n");
raw_gough_report_list rrl(gg[v].reports_eod, rm, remap_reports);
if (rev.find(rrl) != rev.end()) {
reports_eod.push_back(rev[rrl]);
reports_eod.emplace_back(rev[rrl]);
continue;
}
DEBUG_PRINTF("adding to rl eod %zu\n", gg[v].reports_eod.size());
rev[rrl] = ri->size();
reports_eod.push_back(ri->size());
ri->rl.push_back(rrl);
reports_eod.emplace_back(ri->size());
ri->rl.emplace_back(rrl);
}
/* TODO: support single report in gough */
@@ -1313,7 +1313,7 @@ size_t raw_gough_report_info_impl::size() const {
void raw_gough_report_info_impl::fillReportLists(NFA *n, size_t base_offset,
vector<u32> &ro) const {
for (const raw_gough_report_list &r : rl) {
ro.push_back(base_offset);
ro.emplace_back(base_offset);
gough_report_list *p = (gough_report_list *)((char *)n + base_offset);
u32 i = 0;

View File

@@ -145,7 +145,7 @@ void dump_var_mapping(const GoughGraph &g, const string &base,
fprintf(f, "\tuses:");
vector<u32> used_id;
for (const GoughSSAVar *var : used) {
used_id.push_back(var->slot);
used_id.emplace_back(var->slot);
}
for (const u32 &id : used_id) {
fprintf(f, " %u", id);
@@ -167,7 +167,7 @@ void dump_var_mapping(const GoughGraph &g, const string &base,
fprintf(f, "\tuses:");
vector<u32> used_id;
for (const GoughSSAVar *var : used) {
used_id.push_back(var->slot);
used_id.emplace_back(var->slot);
}
for (const u32 &id : used_id) {
fprintf(f, " %u", id);
@@ -194,7 +194,7 @@ void gather_vars(const GoughGraph &g, vector<const GoughSSAVar *> *vars,
const GoughSSAVar *vp = g[v].vars[i].get();
stringstream ss;
ss << dump_name(g[v]) << "_" << i;
vars->push_back(vp);
vars->emplace_back(vp);
names->insert(make_pair(vp, ss.str()));
src_label->insert(make_pair(vp, dump_name(g[v])));
}
@@ -205,7 +205,7 @@ void gather_vars(const GoughGraph &g, vector<const GoughSSAVar *> *vars,
const GoughSSAVar *vp = g[e].vars[i].get();
stringstream ss;
ss << dump_name(g, e) << "_" << i;
vars->push_back(vp);
vars->emplace_back(vp);
names->insert(make_pair(vp, ss.str()));
src_label->insert(make_pair(vp, dump_name(g, e)));
}

View File

@@ -49,19 +49,19 @@ using boost::adaptors::map_values;
namespace ue2 {
template<typename VarP, typename VarQ>
void push_back_all_raw(vector<VarP> *out, const vector<VarQ> &in) {
void emplace_back_all_raw(vector<VarP> *out, const vector<VarQ> &in) {
for (const auto &var : in) {
out->push_back(var.get());
out->emplace_back(var.get());
}
}
static
void all_vars(const GoughGraph &g, vector<GoughSSAVar *> *out) {
for (auto v : vertices_range(g)) {
push_back_all_raw(out, g[v].vars);
emplace_back_all_raw(out, g[v].vars);
}
for (const auto &e : edges_range(g)) {
push_back_all_raw(out, g[e].vars);
emplace_back_all_raw(out, g[e].vars);
}
}
@@ -380,7 +380,7 @@ template<typename VarP>
void add_to_dom_ordering(const vector<VarP> &vars,
vector<GoughSSAVar *> *out) {
for (const auto &var : vars) {
out->push_back(var.get());
out->emplace_back(var.get());
}
}
@@ -389,7 +389,7 @@ class FinishVisitor : public boost::default_dfs_visitor {
public:
explicit FinishVisitor(vector<GoughVertex> *o) : out(o) {}
void finish_vertex(const GoughVertex v, const GoughGraph &) {
out->push_back(v);
out->emplace_back(v);
}
vector<GoughVertex> *out;
};

View File

@@ -331,7 +331,7 @@ void buildReachMapping(const build_info &args, vector<NFAStateSet> &reach,
verts.reserve(args.num_states);
for (auto v : vertices_range(h)) {
if (state_ids.at(v) != NO_STATE) {
verts.push_back(v);
verts.emplace_back(v);
}
}
@@ -362,7 +362,7 @@ void buildReachMapping(const build_info &args, vector<NFAStateSet> &reach,
u8 num = 0;
for (auto mi = mapping.begin(), me = mapping.end(); mi != me; ++mi, ++num) {
// Reach entry.
reach.push_back(mi->first);
reach.emplace_back(mi->first);
// Character mapping.
const CharReach &cr = mi->second;
@@ -427,7 +427,7 @@ void gatherAccelStates(const build_info &bi, vector<AccelBuild> &accelStates) {
DEBUG_PRINTF("state %u is accelerable\n", bi.state_ids.at(v));
AccelBuild a;
findStopLiterals(bi, v, a);
accelStates.push_back(a);
accelStates.emplace_back(a);
}
// AccelStates should be sorted by state number, so that we build our accel
@@ -548,7 +548,7 @@ void filterAccelStates(NGHolder &g, const map<u32, set<NFAVertex>> &tops,
for (const auto &vv : tops | map_values) {
for (NFAVertex v : vv) {
if (!edge(g.start, v, g).second) {
tempEdges.push_back(add_edge(g.start, v, g).first);
tempEdges.emplace_back(add_edge(g.start, v, g).first);
}
}
}
@@ -556,7 +556,7 @@ void filterAccelStates(NGHolder &g, const map<u32, set<NFAVertex>> &tops,
// Similarly, connect (start, startDs) if necessary.
if (!edge(g.start, g.startDs, g).second) {
NFAEdge e = add_edge(g.start, g.startDs, g);
tempEdges.push_back(e); // Remove edge later.
tempEdges.emplace_back(e); // Remove edge later.
}
unordered_map<NFAVertex, AccelScheme> out;
@@ -623,7 +623,7 @@ void fillAccelInfo(build_info &bi) {
vector<NFAVertex> astates;
for (const auto &m : accel_map) {
astates.push_back(m.first);
astates.emplace_back(m.first);
}
NFAStateSet useful(num_states);
@@ -644,7 +644,7 @@ void fillAccelInfo(build_info &bi) {
for (u32 j = 0, j_end = astates.size(); j < j_end; j++) {
if (i & (1U << j)) {
NFAVertex v = astates[j];
states.push_back(v);
states.emplace_back(v);
state_set.set(state_ids.at(v));
}
}
@@ -886,12 +886,12 @@ void buildAccel(const build_info &args, NFAStateSet &accelMask,
// bits in accelStates.
vector<AccelBuild> accelOuts(accelCount);
vector<u32> effective_accel_set;
effective_accel_set.push_back(0); /* empty is effectively empty */
effective_accel_set.emplace_back(0); /* empty is effectively empty */
for (u32 i = 1; i < accelCount; i++) {
u32 effective_i = getEffectiveAccelStates(args, dom_map, i,
accelStates);
effective_accel_set.push_back(effective_i);
effective_accel_set.emplace_back(effective_i);
if (effective_i == IMPOSSIBLE_ACCEL_MASK) {
DEBUG_PRINTF("this combination of accel states is not possible\n");
@@ -913,7 +913,7 @@ void buildAccel(const build_info &args, NFAStateSet &accelMask,
// an index.
// Start with the NONE case.
auxvec.push_back(AccelAux());
auxvec.emplace_back(AccelAux());
memset(&auxvec[0], 0, sizeof(AccelAux));
auxvec[0].accel_type = ACCEL_NONE; // no states on.
@@ -949,7 +949,7 @@ void buildAccel(const build_info &args, NFAStateSet &accelMask,
auto it = find_if(auxvec.begin(), auxvec.end(), AccelAuxCmp(aux));
if (it == auxvec.end()) {
accelTable[i] = verify_u8(auxvec.size());
auxvec.push_back(aux);
auxvec.emplace_back(aux);
} else {
accelTable[i] = verify_u8(it - auxvec.begin());
}
@@ -995,7 +995,7 @@ u32 addSquashMask(const build_info &args, const NFAVertex &v,
return verify_u32(std::distance(squash.begin(), it));
}
u32 idx = verify_u32(squash.size());
squash.push_back(sit->second);
squash.emplace_back(sit->second);
return idx;
}
@@ -1007,7 +1007,7 @@ u32 addReports(const flat_set<ReportID> &r, vector<ReportID> &reports,
assert(!r.empty());
vector<ReportID> my_reports(begin(r), end(r));
my_reports.push_back(MO_INVALID_IDX); // sentinel
my_reports.emplace_back(MO_INVALID_IDX); // sentinel
auto cache_it = reports_cache.find(my_reports);
if (cache_it != end(reports_cache)) {
@@ -1064,7 +1064,7 @@ void buildAcceptsList(const build_info &args, ReportListCache &reports_cache,
a.reports = addReports(h[v].reports, reports, reports_cache);
}
a.squash = addSquashMask(args, v, squash);
accepts.push_back(move(a));
accepts.emplace_back(move(a));
}
}
@@ -1089,11 +1089,11 @@ void buildAccepts(const build_info &args, ReportListCache &reports_cache,
if (edge(v, h.accept, h).second) {
acceptMask.set(state_id);
verts_accept.push_back(v);
verts_accept.emplace_back(v);
} else {
assert(edge(v, h.acceptEod, h).second);
acceptEodMask.set(state_id);
verts_accept_eod.push_back(v);
verts_accept_eod.emplace_back(v);
}
}
@@ -1510,7 +1510,7 @@ u32 buildExceptionMap(const build_info &args, ReportListCache &reports_cache,
// of states.
assert(e.succ_states.size() == num_states);
assert(e.squash_states.size() == num_states);
exceptionMap[e].push_back(i);
exceptionMap[e].emplace_back(i);
exceptionCount++;
}
}
@@ -2513,7 +2513,7 @@ bool isFast(const build_info &args) {
unordered_set<NFAVertex> visited;
for (const auto &m : args.tops) {
for (NFAVertex v : m.second) {
cur.push_back(v);
cur.emplace_back(v);
visited.insert(v);
}
}
@@ -2537,7 +2537,7 @@ bool isFast(const build_info &args) {
continue;
}
if (!contains(visited, w)) {
next.push_back(w);
next.emplace_back(w);
visited.insert(w);
}
}

View File

@@ -354,7 +354,7 @@ static
void setupReach(const u8 *reachMap, const u8 *reachBase, u32 size,
u32 state_count, vector<CharReach> *perStateReach) {
for (u32 i = 0; i < state_count; i++) {
perStateReach->push_back(CharReach());
perStateReach->emplace_back(CharReach());
for (u32 j = 0; j < N_CHARS; j++) {
u8 k = reachMap[j];
const u8 *r = reachBase + k * (size/8);

View File

@@ -162,7 +162,7 @@ DfaPrevInfo::DfaPrevInfo(raw_dfa &rdfa)
for (size_t i = 0; i < states.size(); i++) {
for (symbol_t sym = 0; sym < impl_alpha_size; sym++) {
dstate_id_t curr = rdfa.states[i].next[sym];
states[curr].prev_vec[sym].push_back(i);
states[curr].prev_vec[sym].emplace_back(i);
}
if (!rdfa.states[i].reports.empty()
|| !rdfa.states[i].reports_eod.empty()) {
@@ -398,7 +398,7 @@ unique_ptr<raw_report_info> mcclellan_build_strat::gatherReports(
for (const dstate &s : rdfa.states) {
if (s.reports.empty()) {
reports.push_back(MO_INVALID_IDX);
reports.emplace_back(MO_INVALID_IDX);
continue;
}
@@ -406,18 +406,18 @@ unique_ptr<raw_report_info> mcclellan_build_strat::gatherReports(
DEBUG_PRINTF("non empty r\n");
auto it = rev.find(rrl);
if (it != rev.end()) {
reports.push_back(it->second);
reports.emplace_back(it->second);
} else {
DEBUG_PRINTF("adding to rl %zu\n", ri->size());
rev.emplace(rrl, ri->size());
reports.push_back(ri->size());
ri->rl.push_back(rrl);
reports.emplace_back(ri->size());
ri->rl.emplace_back(rrl);
}
}
for (const dstate &s : rdfa.states) {
if (s.reports_eod.empty()) {
reports_eod.push_back(MO_INVALID_IDX);
reports_eod.emplace_back(MO_INVALID_IDX);
continue;
}
@@ -425,14 +425,14 @@ unique_ptr<raw_report_info> mcclellan_build_strat::gatherReports(
raw_report_list rrl(s.reports_eod, rm, remap_reports);
auto it = rev.find(rrl);
if (it != rev.end()) {
reports_eod.push_back(it->second);
reports_eod.emplace_back(it->second);
continue;
}
DEBUG_PRINTF("adding to rl eod %zu\n", s.reports_eod.size());
rev.emplace(rrl, ri->size());
reports_eod.push_back(ri->size());
ri->rl.push_back(rrl);
reports_eod.emplace_back(ri->size());
ri->rl.emplace_back(rrl);
}
assert(!ri->rl.empty()); /* all components should be able to generate
@@ -484,7 +484,7 @@ size_t raw_report_info_impl::size() const {
void raw_report_info_impl::fillReportLists(NFA *n, size_t base_offset,
vector<u32> &ro) const {
for (const auto &reps : rl) {
ro.push_back(base_offset);
ro.emplace_back(base_offset);
report_list *p = (report_list *)((char *)n + base_offset);
@@ -569,13 +569,13 @@ bool allocateFSN16(dfa_info &info, dstate_id_t *sherman_base,
for (u32 i = 1; i < info.size(); i++) {
if (info.is_widehead(i)) {
wideHead.push_back(i);
wideHead.emplace_back(i);
} else if (info.is_widestate(i)) {
wideState.push_back(i);
wideState.emplace_back(i);
} else if (info.is_sherman(i)) {
sherm.push_back(i);
sherm.emplace_back(i);
} else {
norm.push_back(i);
norm.emplace_back(i);
}
}
@@ -893,11 +893,11 @@ void allocateFSN8(dfa_info &info,
for (u32 i = 1; i < info.size(); i++) {
if (!info.states[i].reports.empty()) {
accept.push_back(i);
accept.emplace_back(i);
} else if (contains(accel_escape_info, i)) {
accel.push_back(i);
accel.emplace_back(i);
} else {
norm.push_back(i);
norm.emplace_back(i);
}
}
@@ -1248,7 +1248,7 @@ dstate_id_t find_chain_candidate(const raw_dfa &rdfa, const DfaPrevInfo &info,
const symbol_t curr_sym,
vector<dstate_id_t> &temp_chain) {
//Record current id first.
temp_chain.push_back(curr_id);
temp_chain.emplace_back(curr_id);
const u16 size = info.impl_alpha_size;
@@ -1311,7 +1311,7 @@ bool store_chain_longest(vector<vector<dstate_id_t>> &candidate_chain,
DEBUG_PRINTF("This is a new chain!\n");
// Add this new chain and get it marked.
candidate_chain.push_back(temp_chain);
candidate_chain.emplace_back(temp_chain);
for (auto &id : temp_chain) {
DEBUG_PRINTF("(Marking s%u ...)\n", id);
@@ -1385,18 +1385,18 @@ void generate_symbol_chain(dfa_info &info, vector<symbol_t> &chain_tail) {
// The tail symbol comes from vector chain_tail;
if (j == width - 1) {
symbol_chain.push_back(chain_tail[i]);
symbol_chain.emplace_back(chain_tail[i]);
} else {
for (symbol_t sym = 0; sym < info.impl_alpha_size; sym++) {
if (rdfa.states[curr_id].next[sym] == next_id) {
symbol_chain.push_back(sym);
symbol_chain.emplace_back(sym);
break;
}
}
}
}
info.wide_symbol_chain.push_back(symbol_chain);
info.wide_symbol_chain.emplace_back(symbol_chain);
}
}
@@ -1445,12 +1445,12 @@ void find_wide_state(dfa_info &info) {
}
reverse(temp_chain.begin(), temp_chain.end());
temp_chain.push_back(curr_id);
temp_chain.emplace_back(curr_id);
assert(head > 0 && head == temp_chain.front());
if (store_chain_longest(info.wide_state_chain, temp_chain,
added, head_is_new)) {
chain_tail.push_back(sym);
chain_tail.emplace_back(sym);
}
}
}

View File

@@ -150,7 +150,7 @@ u32 calc_min_dist_from_bob(raw_dfa &raw, vector<u32> *dist_in) {
continue;
}
if (dist[t] == ~0U) {
to_visit.push_back(t);
to_visit.emplace_back(t);
dist[t] = d + 1;
} else {
assert(dist[t] <= d + 1);

View File

@@ -390,15 +390,15 @@ bool allocateImplId16(dfa_info &info, dstate_id_t sheng_end,
continue; /* sheng impl ids have already been allocated */
} if (info.is_sherman(i)) {
if (info.is_sheng_succ(i)) {
sherm_sheng_succ.push_back(i);
sherm_sheng_succ.emplace_back(i);
} else {
sherm.push_back(i);
sherm.emplace_back(i);
}
} else {
if (info.is_sheng_succ(i)) {
norm_sheng_succ.push_back(i);
norm_sheng_succ.emplace_back(i);
} else {
norm.push_back(i);
norm.emplace_back(i);
}
}
}
@@ -589,7 +589,7 @@ dstate_id_t find_sheng_states(dfa_info &info,
sheng_states.insert(v);
for (const auto &t : adjacent_vertices_range(v, g)) {
if (!contains(considered, g[t].index)) {
to_consider.push_back(t);
to_consider.emplace_back(t);
}
if (t == base_cyclic) {
seen_back_edge = true;
@@ -1279,11 +1279,11 @@ void allocateImplId8(dfa_info &info, dstate_id_t sheng_end,
if (info.is_sheng(i)) {
continue; /* already allocated */
} else if (!info.states[i].reports.empty()) {
accept.push_back(i);
accept.emplace_back(i);
} else if (contains(accel_escape_info, i)) {
accel.push_back(i);
accel.emplace_back(i);
} else {
norm.push_back(i);
norm.emplace_back(i);
}
}

View File

@@ -140,12 +140,12 @@ void populateClusters(const vector<raw_puff> &puffs_in,
u32 e = MQE_TOP_FIRST;
for (const auto &puff : triggered_puffs) {
puff_clusters[ClusterKey(e, puff)].push_back(puff);
puff_clusters[ClusterKey(e, puff)].emplace_back(puff);
e++;
}
for (const auto &puff : puffs_in) {
puff_clusters[ClusterKey(puff)].push_back(puff);
puff_clusters[ClusterKey(puff)].emplace_back(puff);
}
@@ -264,7 +264,7 @@ void fillCounterInfos(vector<mpv_counter_info> *out, u32 *curr_decomp_offset,
assert(it->first.trigger_event
== MQE_TOP_FIRST + distance(kilopuffs.begin(), it));
out->push_back(mpv_counter_info());
out->emplace_back(mpv_counter_info());
map<ClusterKey, vector<raw_puff>>::const_iterator it_o = it;
++it;
fillCounterInfo(&out->back(), curr_decomp_offset, curr_comp_offset,
@@ -282,14 +282,14 @@ void fillCounterInfos(vector<mpv_counter_info> *out, u32 *curr_decomp_offset,
++it;
}
if (it != trig_ite) {
out->push_back(mpv_counter_info());
out->emplace_back(mpv_counter_info());
fillCounterInfo(&out->back(), curr_decomp_offset, curr_comp_offset,
kilopuffs, kilopuffs.begin(), it);
}
while (it != kilopuffs.end() && it->first.auto_restart) {
assert(it->first.trigger_event == MQE_INVALID);
out->push_back(mpv_counter_info());
out->emplace_back(mpv_counter_info());
map<ClusterKey, vector<raw_puff>>::const_iterator it_o = it;
++it;
fillCounterInfo(&out->back(), curr_decomp_offset, curr_comp_offset,

View File

@@ -44,7 +44,7 @@ RdfaGraph::RdfaGraph(const raw_dfa &rdfa) {
vector<RdfaGraph::vertex_descriptor> verts;
verts.reserve(rdfa.states.size());
for (dstate_id_t i = 0; i < rdfa.states.size(); i++) {
verts.push_back(add_vertex(g));
verts.emplace_back(add_vertex(g));
assert(g[verts.back()].index == i);
}

View File

@@ -132,7 +132,7 @@ public:
if (t.any() && t != esets[i]) {
esets[i] &= ~t;
esets.push_back(t);
esets.emplace_back(t);
}
}
}
@@ -204,7 +204,7 @@ public:
const vector<StateSet> initial() {
vector<StateSet> rv = {as};
if (start_floating != DEAD_STATE && start_floating != start_anchored) {
rv.push_back(fs);
rv.emplace_back(fs);
}
return rv;
}
@@ -342,17 +342,17 @@ void mergeDfas(vector<unique_ptr<raw_dfa>> &dfas, size_t max_states,
// Put the larger of the two DFAs on the output list, retain the
// smaller one on the queue for further merge attempts.
if (d2->states.size() > d1->states.size()) {
dfas.push_back(move(d2));
dfas.emplace_back(move(d2));
q.push(move(d1));
} else {
dfas.push_back(move(d1));
dfas.emplace_back(move(d1));
q.push(move(d2));
}
}
}
while (!q.empty()) {
dfas.push_back(move(q.front()));
dfas.emplace_back(move(q.front()));
q.pop();
}

View File

@@ -80,10 +80,10 @@ u32 repeatRecurTable(struct RepeatStateInfo *info, const depth &repeatMax,
u32 repeatTmp = info->patchCount > 2 ? 64 : (u32)repeatMax;
u32 repeat_index = repeatTmp < minPeriod ? repeatTmp : minPeriod;
for (u32 i = 0; i <= repeat_index; i++) {
info->table.push_back(i + 1);
info->table.emplace_back(i + 1);
}
for (u32 i = minPeriod + 1; i <= repeatTmp; i++) {
info->table.push_back(info->table[i - 1] + info->table[i - minPeriod]);
info->table.emplace_back(info->table[i - 1] + info->table[i - minPeriod]);
if (info->table[i] < info->table[i - 1]) {
return i - 1;
}
@@ -341,7 +341,7 @@ vector<size_t> minResetDistToEnd(const vector<vector<CharReach>> &triggers,
break;
}
}
out.push_back(i);
out.emplace_back(i);
}
return out;

View File

@@ -179,7 +179,7 @@ size_t raw_report_info_impl::size() const {
void raw_report_info_impl::fillReportLists(NFA *n, size_t base_offset,
vector<u32> &ro) const {
for (const auto &reps : rl) {
ro.push_back(base_offset);
ro.emplace_back(base_offset);
report_list *p = (report_list *)((char *)n + base_offset);
@@ -208,39 +208,39 @@ unique_ptr<raw_report_info> sheng_build_strat::gatherReports(
for (const dstate &s : rdfa.states) {
if (s.reports.empty()) {
reports.push_back(MO_INVALID_IDX);
reports.emplace_back(MO_INVALID_IDX);
continue;
}
raw_report_list rrl(s.reports, rm, remap_reports);
DEBUG_PRINTF("non empty r\n");
if (rev.find(rrl) != rev.end()) {
reports.push_back(rev[rrl]);
reports.emplace_back(rev[rrl]);
} else {
DEBUG_PRINTF("adding to rl %zu\n", ri->size());
rev[rrl] = ri->size();
reports.push_back(ri->size());
ri->rl.push_back(rrl);
reports.emplace_back(ri->size());
ri->rl.emplace_back(rrl);
}
}
for (const dstate &s : rdfa.states) {
if (s.reports_eod.empty()) {
reports_eod.push_back(MO_INVALID_IDX);
reports_eod.emplace_back(MO_INVALID_IDX);
continue;
}
DEBUG_PRINTF("non empty r eod\n");
raw_report_list rrl(s.reports_eod, rm, remap_reports);
if (rev.find(rrl) != rev.end()) {
reports_eod.push_back(rev[rrl]);
reports_eod.emplace_back(rev[rrl]);
continue;
}
DEBUG_PRINTF("adding to rl eod %zu\n", s.reports_eod.size());
rev[rrl] = ri->size();
reports_eod.push_back(ri->size());
ri->rl.push_back(rrl);
reports_eod.emplace_back(ri->size());
ri->rl.emplace_back(rrl);
}
assert(!ri->rl.empty()); /* all components should be able to generate

View File

@@ -182,7 +182,7 @@ bool shuftiBuildDoubleMasks(const CharReach &onechar,
}
nibble_masks.clear();
for (const auto &e : new_masks) {
nibble_masks.push_back(e.second);
nibble_masks.emplace_back(e.second);
}
}

View File

@@ -54,7 +54,7 @@ void remapTops(const TamaInfo &tamaInfo,
u32 cur = 0;
for (const auto &sub : tamaInfo.subengines) {
u32 base = cur;
top_base.push_back(base + MQE_TOP_FIRST);
top_base.emplace_back(base + MQE_TOP_FIRST);
DEBUG_PRINTF("subengine:%u\n", i);
for (const auto &t : tamaInfo.tops[i++]) {
cur = base + t;
@@ -163,8 +163,8 @@ set<ReportID> all_reports(const TamaProto &proto) {
void TamaInfo::add(NFA *sub, const set<u32> &top) {
assert(subengines.size() < max_occupancy);
subengines.push_back(sub);
tops.push_back(top);
subengines.emplace_back(sub);
tops.emplace_back(top);
}
void TamaProto::add(const NFA *n, const u32 id, const u32 top,