From 243d8bebd1cf1208a9d7b17269ccc148914572a3 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sat, 27 Mar 2021 08:22:31 -0700 Subject: [PATCH] Enable minimal optimizations in debug mode --- include/fmt/core.h | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index 5824dee89b84..5965ce28c64e 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -25,8 +25,10 @@ #if defined(__GNUC__) && !defined(__clang__) # define FMT_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__) +# define FMT_GCC_PRAGMA(arg) _Pragma(arg) #else # define FMT_GCC_VERSION 0 +# define FMT_GCC_PRAGMA(arg) #endif #if defined(__INTEL_COMPILER) @@ -250,6 +252,10 @@ # define FMT_COMPILE_TIME_CHECKS 0 #endif +// Enable minimal optimizations for more compact code in debug mode. +FMT_GCC_PRAGMA("GCC push_options") +FMT_GCC_PRAGMA("GCC optimize(\"Og\")") + FMT_BEGIN_NAMESPACE // Implementations of enable_if_t and other metafunctions for older systems. @@ -387,7 +393,7 @@ template class basic_string_view { #if __cplusplus >= 201703L // C++17's char_traits::length() is constexpr. FMT_CONSTEXPR #endif - basic_string_view(const Char* s) + FMT_INLINE basic_string_view(const Char* s) : data_(s), size_(std::char_traits::length(s)) {} /** Constructs a string reference from a ``std::basic_string`` object. */ @@ -475,7 +481,7 @@ template <> struct is_char : std::true_type {}; \endrst */ template ::value)> -inline basic_string_view to_string_view(const Char* s) { +FMT_INLINE basic_string_view to_string_view(const Char* s) { return s; } @@ -1570,7 +1576,7 @@ class format_arg_store : 0); public: - FMT_CONSTEXPR format_arg_store(const Args&... args) + FMT_CONSTEXPR FMT_INLINE format_arg_store(const Args&... args) : #if FMT_GCC_VERSION && FMT_GCC_VERSION < 409 basic_format_args(*this), @@ -1605,8 +1611,8 @@ constexpr format_arg_store make_format_args( \endrst */ template > -inline auto make_args_checked(const S& format_str, - const remove_reference_t&... args) +FMT_INLINE auto make_args_checked(const S& format_str, + const remove_reference_t&... args) -> format_arg_store, remove_reference_t...> { static_assert( detail::count<( @@ -1943,6 +1949,7 @@ inline void print(const S& format_str, Args&&... args) { : detail::vprint_mojibake(stdout, to_string_view(format_str), vargs); } +FMT_GCC_PRAGMA("GCC pop_options") FMT_END_NAMESPACE #endif // FMT_CORE_H_