boardd: reduce unnecessary allocations (#22494)

pull/22499/head
Adeeb Shihadeh 2021-10-08 16:16:23 -07:00 committed by GitHub
parent 52cd06aa62
commit 2f1ab63920
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 3 deletions

View File

@ -344,10 +344,12 @@ void Panda::send_heartbeat() {
}
void Panda::can_send(capnp::List<cereal::CanData>::Reader can_data_list) {
static std::vector<uint32_t> send;
const int msg_count = can_data_list.size();
const int buf_size = msg_count*0x10;
send.resize(msg_count*0x10);
if (send.size() < buf_size) {
send.resize(buf_size);
}
for (int i = 0; i < msg_count; i++) {
auto cmsg = can_data_list[i];
@ -362,7 +364,7 @@ void Panda::can_send(capnp::List<cereal::CanData>::Reader can_data_list) {
memcpy(&send[i*4+2], can_data.begin(), can_data.size());
}
usb_bulk_write(3, (unsigned char*)send.data(), send.size(), 5);
usb_bulk_write(3, (unsigned char*)send.data(), buf_size, 5);
}
int Panda::can_receive(kj::Array<capnp::word>& out_buf) {

View File

@ -45,6 +45,7 @@ class Panda {
libusb_context *ctx = NULL;
libusb_device_handle *dev_handle = NULL;
std::mutex usb_lock;
std::vector<uint32_t> send;
void handle_usb_issue(int err, const char func[]);
void cleanup();