Skip to content

Commit

Permalink
CANParser: use emplace_back to reduce the cost of copying values (com…
Browse files Browse the repository at this point in the history
  • Loading branch information
deanlee authored and OPGM CI Automated committed Apr 6, 2023
1 parent b0a3c6d commit 5bcfe8c
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions can/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -308,13 +308,12 @@ std::vector<SignalValue> CANParser::query_latest() {

for (int i = 0; i < state.parse_sigs.size(); i++) {
const Signal &sig = state.parse_sigs[i];
ret.push_back((SignalValue){
.address = state.address,
.ts_nanos = state.last_seen_nanos,
.name = sig.name,
.value = state.vals[i],
.all_values = state.all_vals[i],
});
SignalValue &v = ret.emplace_back();
v.address = state.address;
v.ts_nanos = state.last_seen_nanos;
v.name = sig.name;
v.value = state.vals[i];
v.all_values = state.all_vals[i];
state.all_vals[i].clear();
}
}
Expand Down

0 comments on commit 5bcfe8c

Please sign in to comment.