Remove errorIds
The errorIds is used to record the IDs during restore(), and to find the
max element after the restore().
The `entries` is the sorted map so it already has this information.
Remove it and use `entries` directly instead.
Tested: Verify the entryId is assigned correctly in restore().
Signed-off-by: Lei YU <yulei.sh@bytedance.com>
Change-Id: I744e92949193aa7d72d2bb035f1b72fe140fb646
diff --git a/log_manager.cpp b/log_manager.cpp
index 2aa3048..75bab7d 100644
--- a/log_manager.cpp
+++ b/log_manager.cpp
@@ -560,7 +560,6 @@
auto sanity = [](const auto& id, const auto& restoredId) {
return id == restoredId;
};
- std::vector<uint32_t> errorIds;
fs::path dir(ERRLOG_PERSIST_PATH);
if (!fs::exists(dir) || fs::is_empty(dir))
@@ -590,7 +589,6 @@
}
entries.insert(std::make_pair(idNum, std::move(e)));
- errorIds.push_back(idNum);
}
else
{
@@ -602,9 +600,9 @@
}
}
- if (!errorIds.empty())
+ if (!entries.empty())
{
- entryId = *(std::max_element(errorIds.begin(), errorIds.end()));
+ entryId = entries.rbegin()->first;
}
}