mirror of
https://github.com/esphome/esphome.git
synced 2026-09-14 08:38:39 +00:00
[multiple] Remove unnecessary heap allocations in 4 components (#14656)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
08a0608a48
commit
9418f35cc3
@@ -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};
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user