mirror of
https://github.com/esphome/esphome.git
synced 2025-10-31 23:21:54 +00:00
bot comments
This commit is contained in:
@@ -313,10 +313,8 @@ void BLECharacteristic::remove_client_from_notify_list_(uint16_t conn_id) {
|
|||||||
// for the common case by swapping with the last element and popping
|
// for the common case by swapping with the last element and popping
|
||||||
for (size_t i = 0; i < this->clients_to_notify_.size(); i++) {
|
for (size_t i = 0; i < this->clients_to_notify_.size(); i++) {
|
||||||
if (this->clients_to_notify_[i].conn_id == conn_id) {
|
if (this->clients_to_notify_[i].conn_id == conn_id) {
|
||||||
// Swap with last element and pop
|
// Swap with last element and pop (safe even when i is the last element)
|
||||||
if (i != this->clients_to_notify_.size() - 1) {
|
this->clients_to_notify_[i] = this->clients_to_notify_.back();
|
||||||
this->clients_to_notify_[i] = this->clients_to_notify_.back();
|
|
||||||
}
|
|
||||||
this->clients_to_notify_.pop_back();
|
this->clients_to_notify_.pop_back();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,10 +83,8 @@ void BLECharacteristicSetValueActionManager::remove_listener_(BLECharacteristic
|
|||||||
// Since we typically have very few listeners, optimize by swapping with back and popping
|
// Since we typically have very few listeners, optimize by swapping with back and popping
|
||||||
for (size_t i = 0; i < this->listeners_.size(); i++) {
|
for (size_t i = 0; i < this->listeners_.size(); i++) {
|
||||||
if (this->listeners_[i].characteristic == characteristic) {
|
if (this->listeners_[i].characteristic == characteristic) {
|
||||||
// Swap with last element and pop
|
// Swap with last element and pop (safe even when i is the last element)
|
||||||
if (i != this->listeners_.size() - 1) {
|
this->listeners_[i] = this->listeners_.back();
|
||||||
this->listeners_[i] = this->listeners_.back();
|
|
||||||
}
|
|
||||||
this->listeners_.pop_back();
|
this->listeners_.pop_back();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user