aco: Clean up some C++ usages
Iterate over maps by reference to avoid copies. Replace find/insert with insert to avoid double search. Use range-based for loop, avoiding copies by reference. Delete comment. Erase by iterator instead of key to avoid repeat search. Iterators unneeded to modify unwaited_instrs. Use range-based for loop. Reviewed-by: Tony Wasserka <tony.wasserka@gmx.de> Reviewed-by: Rhys Perry <pendingchaos02@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7285>
This commit is contained in:
parent
79347f5cd4
commit
23fb54bf7f
|
@ -313,17 +313,17 @@ struct wait_ctx {
|
|||
pending_flat_vm |= other->pending_flat_vm;
|
||||
pending_s_buffer_store |= other->pending_s_buffer_store;
|
||||
|
||||
for (std::pair<PhysReg,wait_entry> entry : other->gpr_map)
|
||||
for (const std::pair<PhysReg,wait_entry>& entry : other->gpr_map)
|
||||
{
|
||||
std::map<PhysReg,wait_entry>::iterator it = gpr_map.find(entry.first);
|
||||
if (entry.second.logical != logical)
|
||||
continue;
|
||||
|
||||
if (it != gpr_map.end()) {
|
||||
changed |= it->second.join(entry.second);
|
||||
} else {
|
||||
gpr_map.insert(entry);
|
||||
using iterator = std::map<PhysReg,wait_entry>::iterator;
|
||||
const std::pair<iterator, bool> insert_pair = gpr_map.insert(entry);
|
||||
if (insert_pair.second) {
|
||||
changed = true;
|
||||
} else {
|
||||
changed |= insert_pair.first->second.join(entry.second);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -335,16 +335,16 @@ struct wait_ctx {
|
|||
|
||||
/* these are used for statistics, so don't update "changed" */
|
||||
for (unsigned i = 0; i < num_counters; i++) {
|
||||
for (std::pair<Instruction *, unsigned> instr : other->unwaited_instrs[i]) {
|
||||
auto pos = unwaited_instrs[i].find(instr.first);
|
||||
if (pos == unwaited_instrs[i].end())
|
||||
unwaited_instrs[i].insert(instr);
|
||||
else
|
||||
for (const std::pair<Instruction *, unsigned>& instr : other->unwaited_instrs[i]) {
|
||||
using iterator = std::map<Instruction *, unsigned>::iterator;
|
||||
const std::pair<iterator, bool> insert_pair = unwaited_instrs[i].insert(instr);
|
||||
if (!insert_pair.second) {
|
||||
const iterator pos = insert_pair.first;
|
||||
pos->second = std::min(pos->second, instr.second);
|
||||
}
|
||||
}
|
||||
/* don't use a foreach loop to avoid copies */
|
||||
for (auto it = other->reg_instrs[i].begin(); it != other->reg_instrs[i].end(); ++it)
|
||||
reg_instrs[i][it->first].insert(it->second.begin(), it->second.end());
|
||||
for (const std::pair<PhysReg,std::set<Instruction *>>& instr : other->reg_instrs[i])
|
||||
reg_instrs[i][instr.first].insert(instr.second.begin(), instr.second.end());
|
||||
}
|
||||
|
||||
return changed;
|
||||
|
@ -365,7 +365,7 @@ struct wait_ctx {
|
|||
wait_distances[event_idx].push_back(distance);
|
||||
}
|
||||
|
||||
unwaited_instrs[counter_idx].erase(instr);
|
||||
unwaited_instrs[counter_idx].erase(pos);
|
||||
}
|
||||
reg_instrs[counter_idx][reg].clear();
|
||||
}
|
||||
|
@ -376,8 +376,8 @@ struct wait_ctx {
|
|||
void advance_unwaited_instrs()
|
||||
{
|
||||
for (unsigned i = 0; i < num_counters; i++) {
|
||||
for (auto it = unwaited_instrs[i].begin(); it != unwaited_instrs[i].end(); ++it)
|
||||
it->second++;
|
||||
for (std::pair<Instruction * const, unsigned>& instr : unwaited_instrs[i])
|
||||
instr.second++;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue