[multiple] Remove unnecessary heap allocations in 4 components (#14656)

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Jonathan Swoboda
2026-03-09 17:18:44 -04:00
committed by GitHub
co-authored by Claude Opus 4.6
parent 08a0608a48
commit 9418f35cc3
4 changed files with 12 additions and 9 deletions
+5 -4
View File
@@ -350,8 +350,9 @@ bool DaikinArcClimate::on_receive(remote_base::RemoteReceiveData data) {
if (data.expect_item(DAIKIN_HEADER_MARK, DAIKIN_HEADER_SPACE)) {
valid_daikin_frame = true;
size_t bytes_count = data.size() / 2 / 8;
size_t buf_size = bytes_count * 3 + 1;
std::unique_ptr<char[]> buf(new char[buf_size]()); // value-initialize (zero-fill)
// Header (20) + state (19) = 39 bytes max; truncates gracefully via buf_append_printf
char buf[40 * 3 + 1] = {};
constexpr size_t buf_size = sizeof(buf);
size_t buf_pos = 0;
for (size_t i = 0; i < bytes_count; i++) {
uint8_t byte = 0;
@@ -363,9 +364,9 @@ bool DaikinArcClimate::on_receive(remote_base::RemoteReceiveData data) {
break;
}
}
buf_pos = buf_append_printf(buf.get(), buf_size, buf_pos, "%02x ", byte);
buf_pos = buf_append_printf(buf, buf_size, buf_pos, "%02x ", byte);
}
ESP_LOGD(TAG, "WHOLE FRAME %s size: %d", buf.get(), data.size());
ESP_LOGD(TAG, "WHOLE FRAME %s size: %d", buf, data.size());
}
if (!valid_daikin_frame) {
char sbuf[16 * 10 + 1] = {0};
+2 -1
View File
@@ -34,7 +34,8 @@ uint8_t PN7150I2C::read_nfcc(nfc::NciMessage &rx, const uint16_t timeout) {
}
uint8_t PN7150I2C::write_nfcc(nfc::NciMessage &tx) {
if (this->write(tx.encode().data(), tx.encode().size()) == i2c::ERROR_OK) {
auto encoded = tx.encode();
if (this->write(encoded.data(), encoded.size()) == i2c::ERROR_OK) {
return nfc::STATUS_OK;
}
return nfc::STATUS_FAILED;
+2 -1
View File
@@ -34,7 +34,8 @@ uint8_t PN7160I2C::read_nfcc(nfc::NciMessage &rx, const uint16_t timeout) {
}
uint8_t PN7160I2C::write_nfcc(nfc::NciMessage &tx) {
if (this->write(tx.encode().data(), tx.encode().size()) == i2c::ERROR_OK) {
auto encoded = tx.encode();
if (this->write(encoded.data(), encoded.size()) == i2c::ERROR_OK) {
return nfc::STATUS_OK;
}
return nfc::STATUS_FAILED;
+3 -3
View File
@@ -951,10 +951,10 @@ void ToshibaClimate::transmit_ras_2819t_() {
}
uint8_t ToshibaClimate::is_valid_rac_pt1411hwru_header_(const uint8_t *message) {
const std::vector<uint8_t> header{RAC_PT1411HWRU_MESSAGE_HEADER0, RAC_PT1411HWRU_CS_HEADER,
RAC_PT1411HWRU_SWING_HEADER};
static constexpr uint8_t HEADERS[] = {RAC_PT1411HWRU_MESSAGE_HEADER0, RAC_PT1411HWRU_CS_HEADER,
RAC_PT1411HWRU_SWING_HEADER};
for (auto i : header) {
for (auto i : HEADERS) {
if ((message[0] == i) && (message[1] == static_cast<uint8_t>(~i)))
return i;
}