mirror of
https://github.com/esphome/esphome.git
synced 2025-10-30 14:43:51 +00:00
tidy issues
This commit is contained in:
@@ -505,15 +505,15 @@ class APIConnection : public APIServerConnection {
|
|||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~MessageCreator() {
|
~MessageCreator() {
|
||||||
if (has_tagged_string_ptr()) {
|
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.has_tagged_string_ptr()) {
|
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 {
|
||||||
data_ = other.data_;
|
data_ = other.data_;
|
||||||
@@ -527,12 +527,12 @@ 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 (has_tagged_string_ptr()) {
|
if (has_tagged_string_ptr_()) {
|
||||||
delete get_string_ptr();
|
delete get_string_ptr_();
|
||||||
}
|
}
|
||||||
// Copy new data
|
// Copy new data
|
||||||
if (other.has_tagged_string_ptr()) {
|
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 {
|
||||||
data_ = other.data_;
|
data_ = other.data_;
|
||||||
@@ -544,8 +544,8 @@ 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 (has_tagged_string_ptr()) {
|
if (has_tagged_string_ptr_()) {
|
||||||
delete get_string_ptr();
|
delete get_string_ptr_();
|
||||||
}
|
}
|
||||||
// Move data
|
// Move data
|
||||||
data_ = other.data_;
|
data_ = other.data_;
|
||||||
@@ -561,10 +561,10 @@ class APIConnection : public APIServerConnection {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
// Check if this contains a string pointer
|
// Check if this contains a string pointer
|
||||||
bool has_tagged_string_ptr() 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)); }
|
||||||
|
|
||||||
union {
|
union {
|
||||||
MessageCreatorPtr ptr;
|
MessageCreatorPtr ptr;
|
||||||
|
|||||||
Reference in New Issue
Block a user