mirror of
https://github.com/esphome/esphome.git
synced 2025-10-08 21:03:49 +01:00
[esp32_ble] Refactor ESPBTUUID comparison with direct returns and memcmp
This commit is contained in:
@@ -145,28 +145,16 @@ bool ESPBTUUID::operator==(const ESPBTUUID &uuid) const {
|
|||||||
if (this->uuid_.len == uuid.uuid_.len) {
|
if (this->uuid_.len == uuid.uuid_.len) {
|
||||||
switch (this->uuid_.len) {
|
switch (this->uuid_.len) {
|
||||||
case ESP_UUID_LEN_16:
|
case ESP_UUID_LEN_16:
|
||||||
if (uuid.uuid_.uuid.uuid16 == this->uuid_.uuid.uuid16) {
|
return this->uuid_.uuid.uuid16 == uuid.uuid_.uuid.uuid16;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case ESP_UUID_LEN_32:
|
case ESP_UUID_LEN_32:
|
||||||
if (uuid.uuid_.uuid.uuid32 == this->uuid_.uuid.uuid32) {
|
return this->uuid_.uuid.uuid32 == uuid.uuid_.uuid.uuid32;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case ESP_UUID_LEN_128:
|
case ESP_UUID_LEN_128:
|
||||||
for (uint8_t i = 0; i < ESP_UUID_LEN_128; i++) {
|
return memcmp(this->uuid_.uuid.uuid128, uuid.uuid_.uuid.uuid128, ESP_UUID_LEN_128) == 0;
|
||||||
if (uuid.uuid_.uuid.uuid128[i] != this->uuid_.uuid.uuid128[i]) {
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return this->as_128bit() == uuid.as_128bit();
|
return this->as_128bit() == uuid.as_128bit();
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
esp_bt_uuid_t ESPBTUUID::get_uuid() const { return this->uuid_; }
|
esp_bt_uuid_t ESPBTUUID::get_uuid() const { return this->uuid_; }
|
||||||
std::string ESPBTUUID::to_string() const {
|
std::string ESPBTUUID::to_string() const {
|
||||||
|
Reference in New Issue
Block a user