mirror of
https://github.com/esphome/esphome.git
synced 2025-09-13 16:52:18 +01:00
make the bot happy
This commit is contained in:
@@ -485,6 +485,9 @@ class APIConnection : public APIServerConnection {
|
|||||||
|
|
||||||
// Optimized MessageCreator class using tagged pointer
|
// Optimized MessageCreator class using tagged pointer
|
||||||
class MessageCreator {
|
class MessageCreator {
|
||||||
|
// Ensure pointer alignment allows LSB tagging
|
||||||
|
static_assert(alignof(std::string *) > 1, "String pointer alignment must be > 1 for LSB tagging");
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor for function pointer
|
// Constructor for function pointer
|
||||||
MessageCreator(MessageCreatorPtr ptr) {
|
MessageCreator(MessageCreatorPtr ptr) {
|
||||||
@@ -502,14 +505,14 @@ class APIConnection : public APIServerConnection {
|
|||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~MessageCreator() {
|
~MessageCreator() {
|
||||||
if (is_string()) {
|
if (has_tagged_string_ptr()) {
|
||||||
delete get_string_ptr();
|
delete get_string_ptr();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy constructor
|
// Copy constructor
|
||||||
MessageCreator(const MessageCreator &other) {
|
MessageCreator(const MessageCreator &other) {
|
||||||
if (other.is_string()) {
|
if (other.has_tagged_string_ptr()) {
|
||||||
auto *str = new std::string(*other.get_string_ptr());
|
auto *str = new std::string(*other.get_string_ptr());
|
||||||
data_.tagged = reinterpret_cast<uintptr_t>(str) | 1;
|
data_.tagged = reinterpret_cast<uintptr_t>(str) | 1;
|
||||||
} else {
|
} else {
|
||||||
@@ -524,11 +527,11 @@ class APIConnection : public APIServerConnection {
|
|||||||
MessageCreator &operator=(const MessageCreator &other) {
|
MessageCreator &operator=(const MessageCreator &other) {
|
||||||
if (this != &other) {
|
if (this != &other) {
|
||||||
// Clean up current string data if needed
|
// Clean up current string data if needed
|
||||||
if (is_string()) {
|
if (has_tagged_string_ptr()) {
|
||||||
delete get_string_ptr();
|
delete get_string_ptr();
|
||||||
}
|
}
|
||||||
// Copy new data
|
// Copy new data
|
||||||
if (other.is_string()) {
|
if (other.has_tagged_string_ptr()) {
|
||||||
auto *str = new std::string(*other.get_string_ptr());
|
auto *str = new std::string(*other.get_string_ptr());
|
||||||
data_.tagged = reinterpret_cast<uintptr_t>(str) | 1;
|
data_.tagged = reinterpret_cast<uintptr_t>(str) | 1;
|
||||||
} else {
|
} else {
|
||||||
@@ -541,7 +544,7 @@ class APIConnection : public APIServerConnection {
|
|||||||
MessageCreator &operator=(MessageCreator &&other) noexcept {
|
MessageCreator &operator=(MessageCreator &&other) noexcept {
|
||||||
if (this != &other) {
|
if (this != &other) {
|
||||||
// Clean up current string data if needed
|
// Clean up current string data if needed
|
||||||
if (is_string()) {
|
if (has_tagged_string_ptr()) {
|
||||||
delete get_string_ptr();
|
delete get_string_ptr();
|
||||||
}
|
}
|
||||||
// Move data
|
// Move data
|
||||||
@@ -558,7 +561,7 @@ class APIConnection : public APIServerConnection {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
// Check if this contains a string pointer
|
// Check if this contains a string pointer
|
||||||
bool is_string() const { return (data_.tagged & 1) != 0; }
|
bool has_tagged_string_ptr() const { return (data_.tagged & 1) != 0; }
|
||||||
|
|
||||||
// Get the actual string pointer (clears the tag bit)
|
// Get the actual string pointer (clears the tag bit)
|
||||||
std::string *get_string_ptr() const { return reinterpret_cast<std::string *>(data_.tagged & ~uintptr_t(1)); }
|
std::string *get_string_ptr() const { return reinterpret_cast<std::string *>(data_.tagged & ~uintptr_t(1)); }
|
||||||
|
Reference in New Issue
Block a user