diff options
author | arkady-e1ppa <arkady-e1ppa@yandex-team.com> | 2024-06-13 16:50:14 +0300 |
---|---|---|
committer | arkady-e1ppa <arkady-e1ppa@yandex-team.com> | 2024-06-13 17:13:41 +0300 |
commit | 3a8a5fac5ba669fa5bed1ccd92e75bdfc6d30d21 (patch) | |
tree | 6282648de72746e2de7193e12ecc3ee7e4ad40f5 /library/cpp/yt/string/format_string.h | |
parent | 3021b75cb7c16df7e4c99f77ef1509c72a79c876 (diff) | |
download | ydb-3a8a5fac5ba669fa5bed1ccd92e75bdfc6d30d21.tar.gz |
YT-21868: Enable stat analysis in some other places
We slightly rework inner workings of stat analysis. For almost any sane use case the behavior is identical, but should compile a little faster.
If you send string literals like `char[N]` or `const char*` make them constexpr. If you can't (e.g. `ex.what()` case) wrap it in `TStringBuf`, if you want the "by the book; 100% right" solution then wrap it in `TRuntimeFormat` instead.
`SetRequestInfo` methods now statically checks the format. Only one error was found -- hooray!
Some other internal stuff was added, a lot removed -- don't worry about it. You won't be able to see the difference
62050dfe8a9cedc1289f18e80397ff33a8e2ecdb
Diffstat (limited to 'library/cpp/yt/string/format_string.h')
-rw-r--r-- | library/cpp/yt/string/format_string.h | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/library/cpp/yt/string/format_string.h b/library/cpp/yt/string/format_string.h index 8eeab7d99d..0c34763773 100644 --- a/library/cpp/yt/string/format_string.h +++ b/library/cpp/yt/string/format_string.h @@ -12,17 +12,32 @@ namespace NYT { //////////////////////////////////////////////////////////////////////////////// +// Explicitly create TRuntimeFormat if you wish to +// use runtime/non-literal value as format. +class TRuntimeFormat +{ +public: + explicit TRuntimeFormat(TStringBuf fmt); + + TStringBuf Get() const noexcept; + +private: + TStringBuf Format_; +}; + // This class used to properly bind to // string literals and allow compile-time parsing/checking // of those. If you need a runtime format, use TRuntimeFormat template <class... TArgs> -class TBasicStaticFormat +class TBasicFormatString { public: // Can be used to perform compile-time check of format. template <class T> requires std::constructible_from<std::string_view, T> - consteval TBasicStaticFormat(const T& fmt); + consteval TBasicFormatString(const T& fmt); + + TBasicFormatString(TRuntimeFormat fmt); TStringBuf Get() const noexcept; @@ -35,22 +50,9 @@ private: static void CrashCompilerClassIsNotFormattable(); }; -// Explicitly create TRuntimeFormat if you wish to -// use runtime/non-literal value as format. -class TRuntimeFormat -{ -public: - inline explicit TRuntimeFormat(TStringBuf fmt); - - inline TStringBuf Get() const noexcept; - -private: - TStringBuf Format_; -}; - // Used to properly infer template arguments if Format. template <class... TArgs> -using TStaticFormat = TBasicStaticFormat<std::type_identity_t<TArgs>...>; +using TFormatString = TBasicFormatString<std::type_identity_t<TArgs>...>; //////////////////////////////////////////////////////////////////////////////// |