[http_request] Inline apply_manifest_result_main_loop_ into defer lambda

One less method — the logic lives directly in the lambda body.
No flash change (compiler was already inlining the call).
This commit is contained in:
J. Nick Koston
2026-03-17 18:27:53 -10:00
parent 211273d46c
commit e93e064304
2 changed files with 32 additions and 35 deletions
@@ -191,44 +191,42 @@ defer:
// same thread as readers (API, MQTT, web server). This is a single defer for
// both success and error paths to avoid multiple std::function instantiations.
// Lambda captures only 2 pointers (8 bytes) — fits in std::function SBO on all platforms.
this_update->defer([this_update, info]() { this_update->apply_manifest_result_main_loop_(info); });
this_update->defer([this_update, info]() {
if (info->error_str != nullptr) {
this_update->status_set_error(info->error_str);
delete info;
return;
}
// Determine new state on main loop (avoids extra lambda captures from task)
bool trigger_update_available = false;
update::UpdateState new_state;
if (info->latest_version.empty() || info->latest_version == info->current_version) {
new_state = update::UPDATE_STATE_NO_UPDATE;
} else {
new_state = update::UPDATE_STATE_AVAILABLE;
if (this_update->state_ != update::UPDATE_STATE_AVAILABLE) {
trigger_update_available = true;
}
}
this_update->update_info_ = std::move(*info);
this_update->update_info_.has_progress = false;
this_update->update_info_.progress = 0.0f;
this_update->state_ = new_state;
delete info;
this_update->status_clear_error();
this_update->publish_state();
if (trigger_update_available) {
this_update->get_update_available_trigger()->trigger(this_update->update_info_);
}
});
UPDATE_RETURN;
}
void HttpRequestUpdate::apply_manifest_result_main_loop_(update::UpdateInfo *info) {
if (info->error_str != nullptr) {
this->status_set_error(info->error_str);
delete info;
return;
}
// Determine new state on main loop (avoids extra lambda captures from task)
bool trigger_update_available = false;
update::UpdateState new_state;
if (info->latest_version.empty() || info->latest_version == info->current_version) {
new_state = update::UPDATE_STATE_NO_UPDATE;
} else {
new_state = update::UPDATE_STATE_AVAILABLE;
if (this->state_ != update::UPDATE_STATE_AVAILABLE) {
trigger_update_available = true;
}
}
this->update_info_ = std::move(*info);
this->update_info_.has_progress = false;
this->update_info_.progress = 0.0f;
this->state_ = new_state;
delete info;
this->status_clear_error();
this->publish_state();
if (trigger_update_available) {
this->get_update_available_trigger()->trigger(this->update_info_);
}
}
void HttpRequestUpdate::perform(bool force) {
if (this->state_ != update::UPDATE_STATE_AVAILABLE && !force) {
return;
@@ -37,7 +37,6 @@ class HttpRequestUpdate final : public update::UpdateEntity, public PollingCompo
std::string source_url_;
static void update_task(void *params);
void apply_manifest_result_main_loop_(update::UpdateInfo *info);
#ifdef USE_ESP32
TaskHandle_t update_task_handle_{nullptr};
#endif