refactor: switch from folly::gen to ranges

This commit is contained in:
Marcus Holland-Moritz 2024-07-27 15:50:50 +02:00
parent 3ce99d6a43
commit 433bb5e46a
3 changed files with 25 additions and 16 deletions

View File

@ -23,8 +23,7 @@
#include <cassert>
#include <cstdint>
#include <iostream>
#include <folly/gen/Base.h>
#include <ranges>
#include <dwarfs/block_compressor.h>
#include <dwarfs/error.h>
@ -104,10 +103,14 @@ compression_registry::make_decompressor(compression_type type,
void compression_registry::for_each_algorithm(
std::function<void(compression_type, compression_info const&)> const& fn)
const {
using namespace folly::gen;
auto view = std::views::keys(factories_);
std::vector<compression_type> types{view.begin(), view.end()};
from(factories_) | get<0>() | order |
[this, &fn](compression_type type) { fn(type, *factories_.at(type)); };
std::ranges::sort(types);
for (auto type : types) {
fn(type, *factories_.at(type));
}
}
compression_registry::compression_registry() = default;

View File

@ -19,7 +19,7 @@
* along with dwarfs. If not, see <https://www.gnu.org/licenses/>.
*/
#include <folly/gen/Base.h>
#include <ranges>
#include <dwarfs/error.h>
#include <dwarfs/internal/global_entry_data.h>
@ -29,10 +29,12 @@ namespace dwarfs::internal {
template <typename T, typename U>
std::vector<T> global_entry_data::get_vector(map_type<T, U> const& map) const {
using namespace folly::gen;
std::vector<std::pair<T, U>> pairs(map.begin(), map.end());
return from(pairs) | orderBy([](auto const& p) { return p.second; }) |
get<0>() | as<std::vector>();
std::vector<std::pair<T, U>> pairs{map.begin(), map.end()};
std::ranges::sort(pairs, [](auto const& p1, auto const& p2) {
return p1.second < p2.second;
});
auto view = std::views::keys(pairs);
return std::vector<T>{view.begin(), view.end()};
}
auto global_entry_data::get_uids() const -> std::vector<uid_type> {
@ -58,9 +60,13 @@ auto global_entry_data::get_symlinks() const -> std::vector<std::string> {
}
void global_entry_data::index(map_type<std::string, uint32_t>& map) {
using namespace folly::gen;
uint32_t ix = 0;
from(map) | get<0>() | order | [&](std::string const& s) { map[s] = ix++; };
auto keys = std::views::all(map) | std::views::keys;
std::vector<std::string_view> tmp{keys.begin(), keys.end()};
std::ranges::sort(tmp);
std::decay_t<decltype(map)>::mapped_type ix{0};
for (auto& s : tmp) {
map[s] = ix++;
}
}
uint64_t global_entry_data::get_time_offset(uint64_t time) const {

View File

@ -410,15 +410,15 @@ int mkdwarfs_main(int argc, sys_char** argv, iolayer const& iol) {
auto order_desc = "inode fragments order (" + order_parser.choices() + ")";
auto progress_desc = fmt::format(
"progress mode ({})", fmt::join(progress_modes | std::views::keys, ", "));
"progress mode ({})", fmt::join(std::views::keys(progress_modes), ", "));
auto debug_filter_desc =
fmt::format("show effect of filter rules without producing an image ({})",
fmt::join(debug_filter_modes | std::views::keys, ", "));
fmt::join(std::views::keys(debug_filter_modes), ", "));
auto resolution_desc =
fmt::format("time resolution in seconds or ({})",
fmt::join(time_resolutions | std::views::keys, ", "));
fmt::join(std::views::keys(time_resolutions), ", "));
auto hash_list = checksum::available_algorithms();