refactor: simplify loops by using ranges

This commit is contained in:
Marcus Holland-Moritz 2024-08-20 22:41:27 +02:00
parent 0e3ceb0b30
commit a0ff15e7ac

View File

@ -1165,14 +1165,14 @@ void metadata_<LoggerPolicy>::dump(
std::ostream& os, const std::string& indent, directory_view dir, std::ostream& os, const std::string& indent, directory_view dir,
dir_entry_view entry, fsinfo_options const& opts, dir_entry_view entry, fsinfo_options const& opts,
std::function<void(const std::string&, uint32_t)> const& icb) const { std::function<void(const std::string&, uint32_t)> const& icb) const {
auto count = dir.entry_count(); auto range = dir.entry_range();
auto first = dir.first_entry();
os << " (" << count << " entries, parent=" << dir.parent_entry() << ")\n"; os << " (" << range.size() << " entries, parent=" << dir.parent_entry()
<< ")\n";
for (size_t i = 0; i < count; ++i) { for (auto i : range) {
dump(os, indent, make_dir_entry_view(first + i, entry.raw().self_index()), dump(os, indent, make_dir_entry_view(i, entry.raw().self_index()), opts,
opts, icb); icb);
} }
} }
@ -1324,12 +1324,10 @@ nlohmann::json metadata_<LoggerPolicy>::as_json(directory_view dir,
dir_entry_view entry) const { dir_entry_view entry) const {
nlohmann::json arr = nlohmann::json::array(); nlohmann::json arr = nlohmann::json::array();
auto count = dir.entry_count(); auto range = dir.entry_range();
auto first = dir.first_entry();
for (size_t i = 0; i < count; ++i) { for (auto i : range) {
arr.push_back( arr.push_back(as_json(make_dir_entry_view(i, entry.raw().self_index())));
as_json(make_dir_entry_view(first + i, entry.raw().self_index())));
} }
return arr; return arr;