Skip to content

Commit

Permalink
reserve
Browse files Browse the repository at this point in the history
  • Loading branch information
deanlee committed Mar 29, 2024
1 parent f51be6f commit 951793f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions can/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class CANParser {
const int bus;
const DBC *dbc = NULL;
std::unordered_map<uint32_t, MessageState> message_states;
int32_t signal_count = -1;

public:
bool can_valid = false;
Expand Down
8 changes: 8 additions & 0 deletions can/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <cassert>
#include <cstring>
#include <limits>
#include <numeric>
#include <stdexcept>
#include <sstream>

Expand Down Expand Up @@ -257,6 +258,13 @@ void CANParser::query_latest(std::vector<SignalValue> &vals, uint64_t last_ts) {
if (last_ts == 0) {
last_ts = last_nanos;
}

if (signal_count == -1) {
signal_count = std::accumulate(message_states.cbegin(), message_states.cend(), 0, [](int n, auto &it) {
return n + it.second.parse_sigs.size();
});
}
vals.reserve(signal_count);
for (auto& kv : message_states) {
auto& state = kv.second;
if (last_ts != 0 && state.last_seen_nanos < last_ts) {
Expand Down

0 comments on commit 951793f

Please sign in to comment.