[e131] Remove unnecessary heap allocation from packet receive loop (#13852)

This commit is contained in:
J. Nick Koston
2026-02-09 06:42:26 -06:00
committed by GitHub
parent 790ac620ab
commit 22c77866d8
3 changed files with 6 additions and 9 deletions
+2 -5
View File
@@ -55,7 +55,6 @@ void E131Component::setup() {
} }
void E131Component::loop() { void E131Component::loop() {
std::vector<uint8_t> payload;
E131Packet packet; E131Packet packet;
int universe = 0; int universe = 0;
uint8_t buf[1460]; uint8_t buf[1460];
@@ -64,11 +63,9 @@ void E131Component::loop() {
if (len == -1) { if (len == -1) {
return; return;
} }
payload.resize(len);
memmove(&payload[0], buf, len);
if (!this->packet_(payload, universe, packet)) { if (!this->packet_(buf, (size_t) len, universe, packet)) {
ESP_LOGV(TAG, "Invalid packet received of size %zu.", payload.size()); ESP_LOGV(TAG, "Invalid packet received of size %zd.", len);
return; return;
} }
+1 -1
View File
@@ -38,7 +38,7 @@ class E131Component : public esphome::Component {
void set_method(E131ListenMethod listen_method) { this->listen_method_ = listen_method; } void set_method(E131ListenMethod listen_method) { this->listen_method_ = listen_method; }
protected: protected:
bool packet_(const std::vector<uint8_t> &data, int &universe, E131Packet &packet); bool packet_(const uint8_t *data, size_t len, int &universe, E131Packet &packet);
bool process_(int universe, const E131Packet &packet); bool process_(int universe, const E131Packet &packet);
bool join_igmp_groups_(); bool join_igmp_groups_();
void join_(int universe); void join_(int universe);
+3 -3
View File
@@ -116,11 +116,11 @@ void E131Component::leave_(int universe) {
ESP_LOGD(TAG, "Left %d universe for E1.31.", universe); ESP_LOGD(TAG, "Left %d universe for E1.31.", universe);
} }
bool E131Component::packet_(const std::vector<uint8_t> &data, int &universe, E131Packet &packet) { bool E131Component::packet_(const uint8_t *data, size_t len, int &universe, E131Packet &packet) {
if (data.size() < E131_MIN_PACKET_SIZE) if (len < E131_MIN_PACKET_SIZE)
return false; return false;
auto *sbuff = reinterpret_cast<const E131RawPacket *>(&data[0]); auto *sbuff = reinterpret_cast<const E131RawPacket *>(data);
if (memcmp(sbuff->acn_id, ACN_ID, sizeof(sbuff->acn_id)) != 0) if (memcmp(sbuff->acn_id, ACN_ID, sizeof(sbuff->acn_id)) != 0)
return false; return false;