mirror of
https://github.com/fmtlib/fmt.git
synced 2025-07-30 10:47:35 +02:00
Improve debug codegen
This commit is contained in:
@ -78,6 +78,11 @@
|
|||||||
#else
|
#else
|
||||||
# define FMT_HAS_INCLUDE(x) 0
|
# define FMT_HAS_INCLUDE(x) 0
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef __has_builtin
|
||||||
|
# define FMT_HAS_BUILTIN(x) __has_builtin(x)
|
||||||
|
#else
|
||||||
|
# define FMT_HAS_BUILTIN(x) 0
|
||||||
|
#endif
|
||||||
#ifdef __has_cpp_attribute
|
#ifdef __has_cpp_attribute
|
||||||
# define FMT_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x)
|
# define FMT_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x)
|
||||||
#else
|
#else
|
||||||
@ -455,6 +460,9 @@ constexpr auto is_utf8_enabled() -> bool { return "\u00A7"[1] == '\xA7'; }
|
|||||||
// It is a macro for better debug codegen without if constexpr.
|
// It is a macro for better debug codegen without if constexpr.
|
||||||
#define FMT_USE_UTF8 (!FMT_MSC_VERSION || fmt::detail::is_utf8_enabled())
|
#define FMT_USE_UTF8 (!FMT_MSC_VERSION || fmt::detail::is_utf8_enabled())
|
||||||
|
|
||||||
|
template <typename T> constexpr const char* narrow(const T*) { return nullptr; }
|
||||||
|
constexpr FMT_ALWAYS_INLINE const char* narrow(const char* s) { return s; }
|
||||||
|
|
||||||
#ifndef FMT_UNICODE
|
#ifndef FMT_UNICODE
|
||||||
# define FMT_UNICODE 1
|
# define FMT_UNICODE 1
|
||||||
#endif
|
#endif
|
||||||
@ -462,12 +470,6 @@ constexpr auto is_utf8_enabled() -> bool { return "\u00A7"[1] == '\xA7'; }
|
|||||||
static_assert(!FMT_UNICODE || FMT_USE_UTF8,
|
static_assert(!FMT_UNICODE || FMT_USE_UTF8,
|
||||||
"Unicode support requires compiling with /utf-8");
|
"Unicode support requires compiling with /utf-8");
|
||||||
|
|
||||||
template <typename Char> FMT_CONSTEXPR auto length(const Char* s) -> size_t {
|
|
||||||
size_t len = 0;
|
|
||||||
while (*s++) ++len;
|
|
||||||
return len;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename Char>
|
template <typename Char>
|
||||||
FMT_CONSTEXPR auto compare(const Char* s1, const Char* s2, std::size_t n)
|
FMT_CONSTEXPR auto compare(const Char* s1, const Char* s2, std::size_t n)
|
||||||
-> int {
|
-> int {
|
||||||
@ -536,13 +538,20 @@ template <typename Char> class basic_string_view {
|
|||||||
constexpr basic_string_view(std::nullptr_t) = delete;
|
constexpr basic_string_view(std::nullptr_t) = delete;
|
||||||
|
|
||||||
/// Constructs a string reference object from a C string.
|
/// Constructs a string reference object from a C string.
|
||||||
FMT_CONSTEXPR20
|
#if FMT_GCC_VERSION
|
||||||
basic_string_view(const Char* s)
|
FMT_ALWAYS_INLINE
|
||||||
: data_(s),
|
#endif
|
||||||
size_(detail::const_check(std::is_same<Char, char>::value &&
|
FMT_CONSTEXPR20 basic_string_view(const Char* s) : data_(s) {
|
||||||
!detail::is_constant_evaluated(false))
|
#if FMT_HAS_BUILTIN(__buitin_strlen) || FMT_GCC_VERSION || FMT_CLANG_VERSION
|
||||||
? strlen(reinterpret_cast<const char*>(s))
|
if (std::is_same<Char, char>::value) {
|
||||||
: detail::length(s)) {}
|
size_ = __builtin_strlen(detail::narrow(s));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
size_t len = 0;
|
||||||
|
while (*s++) ++len;
|
||||||
|
size_ = len;
|
||||||
|
}
|
||||||
|
|
||||||
/// Constructs a string reference from a `std::basic_string` or a
|
/// Constructs a string reference from a `std::basic_string` or a
|
||||||
/// `std::basic_string_view` object.
|
/// `std::basic_string_view` object.
|
||||||
|
@ -81,12 +81,6 @@
|
|||||||
# define FMT_SO_VISIBILITY(value)
|
# define FMT_SO_VISIBILITY(value)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __has_builtin
|
|
||||||
# define FMT_HAS_BUILTIN(x) __has_builtin(x)
|
|
||||||
#else
|
|
||||||
# define FMT_HAS_BUILTIN(x) 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if FMT_GCC_VERSION || FMT_CLANG_VERSION
|
#if FMT_GCC_VERSION || FMT_CLANG_VERSION
|
||||||
# define FMT_NOINLINE __attribute__((noinline))
|
# define FMT_NOINLINE __attribute__((noinline))
|
||||||
#else
|
#else
|
||||||
|
Reference in New Issue
Block a user