From 6f36face98071fc5f29c7d73ca742b549c1ae83f Mon Sep 17 00:00:00 2001 From: deanlee Date: Sun, 9 Jun 2024 15:11:31 +0800 Subject: [PATCH] pre-alloc tmp_vals --- can/common.h | 1 + can/parser.cc | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/can/common.h b/can/common.h index 46b3159b9f..0134729b60 100644 --- a/can/common.h +++ b/can/common.h @@ -43,6 +43,7 @@ class MessageState { std::vector parse_sigs; std::vector vals; std::vector> all_vals; + std::vector tmp_vals; uint64_t last_seen_nanos; uint64_t check_threshold; diff --git a/can/parser.cc b/can/parser.cc index d36ec75bad..153e811894 100644 --- a/can/parser.cc +++ b/can/parser.cc @@ -33,7 +33,6 @@ int64_t get_raw_value(const std::vector &msg, const Signal &sig) { bool MessageState::parse(uint64_t nanos, const std::vector &dat) { - std::vector tmp_vals(parse_sigs.size()); bool checksum_failed = false; bool counter_failed = false; @@ -128,6 +127,7 @@ CANParser::CANParser(int abus, const std::string& dbc_name, const std::vectorsigs; state.vals.resize(msg->sigs.size()); state.all_vals.resize(msg->sigs.size()); + state.tmp_vals.resize(msg->sigs.size()); } } @@ -147,6 +147,7 @@ CANParser::CANParser(int abus, const std::string& dbc_name, bool ignore_checksum .ignore_counter = ignore_counter, }; + state.tmp_vals.resize(msg.sigs.size()); for (const auto& sig : msg.sigs) { state.parse_sigs.push_back(sig); state.vals.push_back(0);