mirror of
https://github.com/esphome/esphome.git
synced 2025-09-08 14:22:21 +01:00
Merge branch 'integration' into memory_api
This commit is contained in:
@@ -425,14 +425,14 @@ void AsyncEventSourceResponse::destroy(void *ptr) {
|
|||||||
void AsyncEventSourceResponse::deq_push_back_with_dedup_(void *source, message_generator_t *message_generator) {
|
void AsyncEventSourceResponse::deq_push_back_with_dedup_(void *source, message_generator_t *message_generator) {
|
||||||
DeferredEvent item(source, message_generator);
|
DeferredEvent item(source, message_generator);
|
||||||
|
|
||||||
auto iter = std::find_if(this->deferred_queue_.begin(), this->deferred_queue_.end(),
|
// Replace std::find_if with simple loop to reduce binary size
|
||||||
[&item](const DeferredEvent &test) -> bool { return test == item; });
|
for (auto &event : this->deferred_queue_) {
|
||||||
|
if (event == item) {
|
||||||
if (iter != this->deferred_queue_.end()) {
|
event = item;
|
||||||
(*iter) = item;
|
return;
|
||||||
} else {
|
|
||||||
this->deferred_queue_.push_back(item);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
this->deferred_queue_.push_back(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AsyncEventSourceResponse::process_deferred_queue_() {
|
void AsyncEventSourceResponse::process_deferred_queue_() {
|
||||||
|
@@ -497,24 +497,24 @@ void Application::unregister_socket_fd(int fd) {
|
|||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto it = std::find(this->socket_fds_.begin(), this->socket_fds_.end(), fd);
|
for (size_t i = 0; i < this->socket_fds_.size(); i++) {
|
||||||
if (it != this->socket_fds_.end()) {
|
if (this->socket_fds_[i] != fd)
|
||||||
|
continue;
|
||||||
|
|
||||||
// Swap with last element and pop - O(1) removal since order doesn't matter
|
// Swap with last element and pop - O(1) removal since order doesn't matter
|
||||||
if (it != this->socket_fds_.end() - 1) {
|
if (i < this->socket_fds_.size() - 1)
|
||||||
std::swap(*it, this->socket_fds_.back());
|
this->socket_fds_[i] = this->socket_fds_.back();
|
||||||
}
|
|
||||||
this->socket_fds_.pop_back();
|
this->socket_fds_.pop_back();
|
||||||
this->socket_fds_changed_ = true;
|
this->socket_fds_changed_ = true;
|
||||||
|
|
||||||
// Only recalculate max_fd if we removed the current max
|
// Only recalculate max_fd if we removed the current max
|
||||||
if (fd == this->max_fd_) {
|
if (fd == this->max_fd_) {
|
||||||
if (this->socket_fds_.empty()) {
|
|
||||||
this->max_fd_ = -1;
|
this->max_fd_ = -1;
|
||||||
} else {
|
for (int sock_fd : this->socket_fds_)
|
||||||
// Find new max using std::max_element
|
if (sock_fd > this->max_fd_)
|
||||||
this->max_fd_ = *std::max_element(this->socket_fds_.begin(), this->socket_fds_.end());
|
this->max_fd_ = sock_fd;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user