From 04e0dfd4bd5b264c8be96dfdb8d13a1e563f7b69 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sun, 19 Apr 2020 07:41:55 -0700 Subject: [PATCH] Always inline value ctors --- include/fmt/core.h | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index fa317cef..45bb134f 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -170,6 +170,14 @@ # endif #endif +#ifndef FMT_INLINE +# if FMT_GCC_VERSION +# define FMT_INLINE __attribute__((always_inline)) +# else +# define FMT_INLINE +# endif +#endif + // Workaround broken [[deprecated]] in the Intel, PGI and NVCC compilers. #if FMT_ICC_VERSION || defined(__PGI) || FMT_NVCC # define FMT_DEPRECATED_ALIAS @@ -923,27 +931,27 @@ template class value { named_arg_value named_args; }; - FMT_CONSTEXPR value(int val = 0) : int_value(val) {} - FMT_CONSTEXPR value(unsigned val) : uint_value(val) {} - value(long long val) : long_long_value(val) {} - value(unsigned long long val) : ulong_long_value(val) {} - value(int128_t val) : int128_value(val) {} - value(uint128_t val) : uint128_value(val) {} - value(float val) : float_value(val) {} - value(double val) : double_value(val) {} - value(long double val) : long_double_value(val) {} - value(bool val) : bool_value(val) {} - value(char_type val) : char_value(val) {} - value(const char_type* val) { string.data = val; } - value(basic_string_view val) { + FMT_CONSTEXPR FMT_INLINE value(int val = 0) : int_value(val) {} + FMT_CONSTEXPR FMT_INLINE value(unsigned val) : uint_value(val) {} + FMT_INLINE value(long long val) : long_long_value(val) {} + FMT_INLINE value(unsigned long long val) : ulong_long_value(val) {} + FMT_INLINE value(int128_t val) : int128_value(val) {} + FMT_INLINE value(uint128_t val) : uint128_value(val) {} + FMT_INLINE value(float val) : float_value(val) {} + FMT_INLINE value(double val) : double_value(val) {} + FMT_INLINE value(long double val) : long_double_value(val) {} + FMT_INLINE value(bool val) : bool_value(val) {} + FMT_INLINE value(char_type val) : char_value(val) {} + FMT_INLINE value(const char_type* val) { string.data = val; } + FMT_INLINE value(basic_string_view val) { string.data = val.data(); string.size = val.size(); } - value(const void* val) : pointer(val) {} - value(const named_arg_info* args, size_t size) + FMT_INLINE value(const void* val) : pointer(val) {} + FMT_INLINE value(const named_arg_info* args, size_t size) : named_args{args, size} {} - template value(const T& val) { + template FMT_INLINE value(const T& val) { custom.value = &val; // Get the formatter type through the context to allow different contexts // have different extension points, e.g. `formatter` for `format` and @@ -1741,7 +1749,7 @@ inline void vprint_mojibake(std::FILE*, string_view, format_args) {} */ template inline internal::named_arg arg(const Char* name, const T& arg) { - static_assert(!internal::is_named_arg(), ""); + static_assert(!internal::is_named_arg(), "nested named arguments"); return {name, arg}; }