Skip to content

Commit

Permalink
migrate to fmt::format in fb303/
Browse files Browse the repository at this point in the history
Reviewed By: Gownta

Differential Revision: D67565140

fbshipit-source-id: c5492707706290d2c9db192f6b8f2c35932adc85
  • Loading branch information
yfeldblum authored and facebook-github-bot committed Jan 4, 2025
1 parent 4b51880 commit 5a01c81
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions fb303/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ cpp_library(
"//folly:singleton",
],
exported_deps = [
"fbsource//third-party/fmt:fmt",
":export_type",
":simple_lru_map",
":thread_local_stats_map",
Expand Down
13 changes: 12 additions & 1 deletion fb303/ThreadCachedServiceData.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include <utility>
#include <variant>

#include <fmt/format.h>

#include <fb303/ExportType.h>
#include <fb303/SimpleLRUMap.h>
#include <fb303/ThreadLocalStatsMap.h>
Expand Down Expand Up @@ -770,7 +772,8 @@ class FormattedKeyHolder {
[](int64_t v) { return std::to_string(v); },
[](std::string const& v) { return v; });
}
auto formattedKey = folly::svformat(keyFormat_, subkeyStrings);
auto formattedKey = doFormatKeyGlobal(
keyFormat_, subkeyStrings, std::make_index_sequence<N>{});
if (prepareKey_) {
prepareKey_(formattedKey);
}
Expand All @@ -780,6 +783,14 @@ class FormattedKeyHolder {
return ReturnType(iter->first, iter->second);
}

template <size_t... Idx>
static std::string doFormatKeyGlobal(
std::string_view keyFormat,
std::array<std::string, N> subkeyStrings,
std::index_sequence<Idx...>) {
return fmt::format(fmt::runtime(keyFormat), subkeyStrings[Idx]...);
}

private:
std::string keyFormat_;
std::function<void(const std::string& key)> prepareKey_;
Expand Down

0 comments on commit 5a01c81

Please sign in to comment.