Skip to content

Commit 3e80fa6

Browse files
committed
log_files: use some algorithms where applicable
1 parent 6348dd4 commit 3e80fa6

File tree

1 file changed

+15
-19
lines changed

1 file changed

+15
-19
lines changed

src/mavsdk/plugins/log_files/log_files_impl.cpp

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -193,23 +193,22 @@ void LogFilesImpl::process_log_entry(const mavlink_message_t& message)
193193
_log_entries[msg.id] = new_entry;
194194

195195
// Check if all entries are received
196-
bool all_received = true;
197-
for (const auto& entry_opt : _log_entries) {
198-
if (!entry_opt.has_value()) {
199-
all_received = false;
200-
break;
201-
}
202-
}
196+
bool all_received =
197+
std::all_of(_log_entries.begin(), _log_entries.end(), [](const auto& entry_opt) {
198+
return entry_opt.has_value();
199+
});
203200

204201
if (all_received) {
205202
_system_impl->unregister_timeout_handler(_entries_timeout_cookie);
206203

207204
// Build result list from vector (safe since all entries are present)
208-
std::vector<LogFiles::Entry> entry_list{};
205+
std::vector<LogFiles::Entry> entry_list;
209206
entry_list.reserve(_log_entries.size());
210-
for (const auto& entry_opt : _log_entries) {
211-
entry_list.push_back(entry_opt.value());
212-
}
207+
std::transform(
208+
_log_entries.begin(),
209+
_log_entries.end(),
210+
std::back_inserter(entry_list),
211+
[](const auto& entry_opt) { return entry_opt.value(); });
213212

214213
const auto cb = _entries_user_callback;
215214
if (cb) {
@@ -392,13 +391,11 @@ void LogFilesImpl::process_log_data(const mavlink_message_t& message)
392391
_download_data.chunk_bin_table[bin] = true;
393392

394393
// Check if all bins in the chunk have been received
395-
bool chunk_complete = true;
396-
for (uint32_t i = 0; i < _download_data.bins_in_chunk(); ++i) {
397-
if (!_download_data.chunk_bin_table[i]) {
398-
chunk_complete = false;
399-
break;
400-
}
401-
}
394+
const uint32_t bins_in_chunk = _download_data.bins_in_chunk();
395+
bool chunk_complete = std::all_of(
396+
_download_data.chunk_bin_table.begin(),
397+
_download_data.chunk_bin_table.begin() + bins_in_chunk,
398+
[](bool received) { return received; });
402399

403400
if (chunk_complete) {
404401
uint32_t chunk_bytes = _download_data.current_chunk_size();
@@ -438,7 +435,6 @@ void LogFilesImpl::process_log_data(const mavlink_message_t& message)
438435
// Check for missing bins when we might have all bins for this chunk
439436
// This handles: receiving the last expected bin AND receiving retried bins that might
440437
// complete the chunk
441-
const uint32_t bins_in_chunk = _download_data.bins_in_chunk();
442438
if (bins_in_chunk > 0) {
443439
const uint32_t expected_last_bin = bins_in_chunk - 1;
444440
// Check if this could be the last bin we need (either the expected last one, or a

0 commit comments

Comments
 (0)