[core] Fix the performance and modernize findings of clang-tidy 23 (#21336)

This commit is contained in:
Jonathan Swoboda
2026-10-22 02:03:00 +00:00
committed by GitHub
parent 01b29dbf53
commit fbc4bc9e10
10 changed files with 15 additions and 14 deletions
@@ -1,6 +1,7 @@
#pragma once
#include <cinttypes>
#include <utility>
#include "esphome/core/component.h"
#include "esphome/core/preferences.h"
@@ -26,7 +27,7 @@ class DutyTimeSensor final : public sensor::Sensor, public PollingComponent {
#ifdef USE_BINARY_SENSOR
void set_sensor(binary_sensor::BinarySensor *sensor);
#endif
void set_lambda(std::function<bool()> &&func) { this->func_ = func; }
void set_lambda(std::function<bool()> &&func) { this->func_ = std::move(func); }
void set_last_duty_time_sensor(sensor::Sensor *sensor) { this->last_duty_time_sensor_ = sensor; }
void set_restore(bool restore) { this->restore_ = restore; }
+2 -2
View File
@@ -407,7 +407,7 @@ void LD2410Component::handle_periodic_data_() {
}
#ifdef USE_NUMBER
std::function<void(void)> set_number_value(number::Number *n, float value) {
std::function<void()> set_number_value(number::Number *n, float value) {
if (n != nullptr && (!n->has_state() || n->state != value)) {
n->state = value;
return [n, value]() { n->publish_state(value); };
@@ -560,7 +560,7 @@ bool LD2410Component::handle_ack_data_() {
Moving distance range: 13th byte
Still distance range: 14th byte
*/
std::vector<std::function<void(void)>> updates;
std::vector<std::function<void()>> updates;
updates.push_back(set_number_value(this->max_move_distance_gate_number_, this->buffer_data_[12]));
updates.push_back(set_number_value(this->max_still_distance_gate_number_, this->buffer_data_[13]));
/*
@@ -652,7 +652,7 @@ ModbusCommandItem ModbusCommandItem::create_custom_command(
ESP_LOGI(TAG, "Custom Command sent");
};
} else {
cmd.on_data_func = handler;
cmd.on_data_func = std::move(handler);
}
cmd.payload.set(values.data(), values.size());
@@ -669,7 +669,7 @@ ModbusCommandItem ModbusCommandItem::create_custom_command(
ESP_LOGI(TAG, "Custom Command sent");
};
} else {
cmd.on_data_func = handler;
cmd.on_data_func = std::move(handler);
}
uint8_t *p = cmd.payload.init(values.size() * 2);
for (auto v : values) {
+2 -2
View File
@@ -28,12 +28,12 @@ std::string get_random_ha_tag_ndef() {
for (int i = 0; i < 8; i++) {
uri += ALPHANUM[random_uint32() % (sizeof(ALPHANUM) - 1)];
}
uri += "-";
uri += '-';
for (int j = 0; j < 3; j++) {
for (int i = 0; i < 4; i++) {
uri += ALPHANUM[random_uint32() % (sizeof(ALPHANUM) - 1)];
}
uri += "-";
uri += '-';
}
for (int i = 0; i < 12; i++) {
uri += ALPHANUM[random_uint32() % (sizeof(ALPHANUM) - 1)];
+1 -1
View File
@@ -147,7 +147,7 @@ void RFBridgeComponent::finish_bucket_frame_() {
buckets--;
}
if ((i < 3) || (buckets % 2) || (i == at - 1)) {
str += " ";
str += ' ';
}
}
ESP_LOGI(TAG, "Received RFBridge Bucket: %s", str.c_str());
+1 -1
View File
@@ -331,7 +331,7 @@ void Sim800LComponent::parse_cmd_(std::string message) {
this->state_ = STATE_RECEIVED_SMS;
} else {
if (!this->message_.empty())
this->message_ += "\n";
this->message_ += '\n';
this->message_ += message;
}
break;
+1 -1
View File
@@ -108,7 +108,7 @@ bool check_sml_data(const bytes &buffer) {
uint16_t crc_received = (buffer.at(buffer.size() - 2) << 8) | buffer.at(buffer.size() - 1);
uint16_t crc_calculated = crc16(buffer.data() + 8, buffer.size() - 10, 0x6e23, 0x8408, true, true);
crc_calculated = (crc_calculated >> 8) | (crc_calculated << 8);
crc_calculated = byteswap(crc_calculated);
if (crc_received == crc_calculated) {
ESP_LOGV(TAG, "Checksum verification successful with CRC16/X25.");
return true;
+2 -2
View File
@@ -2,6 +2,7 @@
#include "esphome/core/application.h"
#include "esphome/core/component.h"
#include "esphome/core/hal.h"
#include "esphome/core/helpers.h"
#include "esphome/core/log.h"
#include <map>
#include <utility>
@@ -224,8 +225,7 @@ class SPIDelegate {
// write 16 bits
virtual void write16(uint16_t data) {
if (this->bit_order_ == BIT_ORDER_MSB_FIRST) {
uint16_t buffer;
buffer = (data >> 8) | (data << 8);
uint16_t buffer = byteswap(data);
this->write_array(reinterpret_cast<const uint8_t *>(&buffer), 2);
} else {
this->write_array(reinterpret_cast<const uint8_t *>(&data), 2);
@@ -357,7 +357,7 @@ void VoiceAssistant::loop() {
msg.start = true;
msg.conversation_id = StringRef(this->conversation_id_);
msg.flags = flags;
msg.audio_settings = audio_settings;
msg.audio_settings = std::move(audio_settings);
msg.wake_word_phrase = StringRef(this->wake_word_);
// Reset media player state tracking
+1 -1
View File
@@ -115,7 +115,7 @@ int ZephyrPreferences::load_setting(const char *name, size_t len, settings_read_
auto type = parse_hex<uint32_t>(name);
if (!type.has_value()) {
std::string full_name(ESPHOME_SETTINGS_KEY);
full_name += "/";
full_name += '/';
full_name += name;
// Delete unusable keys. Otherwise it will stay in flash forever.
settings_delete(full_name.c_str());