From a9b7bf35b1842c478d5cc4ea1248687aeacfb735 Mon Sep 17 00:00:00 2001 From: Marcus Holland-Moritz Date: Sat, 6 Mar 2021 14:47:47 +0100 Subject: [PATCH] Use string_view in mapping --- src/dwarfs/fstypes.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/dwarfs/fstypes.cpp b/src/dwarfs/fstypes.cpp index 1496908b..e3fff37c 100644 --- a/src/dwarfs/fstypes.cpp +++ b/src/dwarfs/fstypes.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include @@ -33,7 +34,7 @@ namespace dwarfs { namespace { -const std::map sections{ +const std::map sections{ #define SECTION_TYPE_(x) {section_type::x, #x} SECTION_TYPE_(BLOCK), SECTION_TYPE_(METADATA_V2_SCHEMA), @@ -41,7 +42,7 @@ const std::map sections{ #undef SECTION_TYPE_ }; -const std::map compressions{ +const std::map compressions{ #define COMPRESSION_TYPE_(x) {compression_type::x, #x} COMPRESSION_TYPE_(NONE), COMPRESSION_TYPE_(LZMA), COMPRESSION_TYPE_(ZSTD), COMPRESSION_TYPE_(LZ4), COMPRESSION_TYPE_(LZ4HC) @@ -49,15 +50,12 @@ const std::map compressions{ }; template -typename HT::mapped_type -get_default(const HT& ht, const typename HT::key_type& key) { - auto i = ht.find(key); - - if (i != ht.end()) { - return i->second; +std::string get_default(const HT& ht, const typename HT::key_type& key) { + if (auto it = ht.find(key); it != ht.end()) { + return folly::to(it->second); } - return folly::to("unknown (", key, ")"); + return folly::to("unknown (", key, ")"); } } // namespace