diff --git a/include/dwarfs/writer/internal/global_entry_data.h b/include/dwarfs/writer/internal/global_entry_data.h index 3601ea7d..d1fb100f 100644 --- a/include/dwarfs/writer/internal/global_entry_data.h +++ b/include/dwarfs/writer/internal/global_entry_data.h @@ -26,7 +26,7 @@ #include #include -#include +#include #include @@ -59,10 +59,7 @@ class global_entry_data { void add_name(std::string const& name) { names_.emplace(name, 0); } void add_link(std::string const& link) { symlinks_.emplace(link, 0); } - void index() { - index(names_); - index(symlinks_); - } + void index(); size_t get_uid_index(uid_type uid) const; size_t get_gid_index(gid_type gid) const; @@ -86,13 +83,11 @@ class global_entry_data { private: template - using map_type = folly::F14FastMap; + using map_type = phmap::flat_hash_map; template std::vector get_vector(map_type const& map) const; - static void index(map_type& map); - template void add(T val, map_type& map, T& next_index) { if (map.emplace(val, next_index).second) { diff --git a/src/writer/internal/global_entry_data.cpp b/src/writer/internal/global_entry_data.cpp index 304a6ef2..3cf01b92 100644 --- a/src/writer/internal/global_entry_data.cpp +++ b/src/writer/internal/global_entry_data.cpp @@ -30,6 +30,22 @@ namespace dwarfs::writer::internal { +namespace { + +template +void index_map(MapT& map) { + using mapped_type = typename MapT::mapped_type; + static_assert(std::is_integral_v); + auto keys = map | ranges::views::keys | ranges::to; + ranges::sort(keys); + mapped_type ix{0}; + for (auto& k : keys) { + map[k] = ix++; + } +} + +} // namespace + template std::vector global_entry_data::get_vector(map_type const& map) const { std::vector> pairs{map.begin(), map.end()}; @@ -59,13 +75,9 @@ auto global_entry_data::get_symlinks() const -> std::vector { return get_vector(symlinks_); } -void global_entry_data::index(map_type& map) { - auto keys = map | ranges::views::keys | ranges::to; - ranges::sort(keys); - std::decay_t::mapped_type ix{0}; - for (auto& k : keys) { - map[k] = ix++; - } +void global_entry_data::index() { + index_map(names_); + index_map(symlinks_); } uint64_t global_entry_data::get_time_offset(uint64_t time) const {