mirror of
https://github.com/fmtlib/fmt.git
synced 2025-07-30 10:47:35 +02:00
Avoiding __builtin_strlen (#4429)
This commit is contained in:
@ -539,7 +539,7 @@ template <typename Char> class basic_string_view {
|
|||||||
#endif
|
#endif
|
||||||
FMT_CONSTEXPR20 basic_string_view(const Char* s) : data_(s) {
|
FMT_CONSTEXPR20 basic_string_view(const Char* s) : data_(s) {
|
||||||
#if FMT_HAS_BUILTIN(__builtin_strlen) || FMT_GCC_VERSION || FMT_CLANG_VERSION
|
#if FMT_HAS_BUILTIN(__builtin_strlen) || FMT_GCC_VERSION || FMT_CLANG_VERSION
|
||||||
if (std::is_same<Char, char>::value) {
|
if (std::is_same<Char, char>::value && !detail::is_constant_evaluated()) {
|
||||||
size_ = __builtin_strlen(detail::narrow(s));
|
size_ = __builtin_strlen(detail::narrow(s));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -92,6 +92,29 @@ TEST(string_view_test, compare) {
|
|||||||
check_op<std::greater_equal>();
|
check_op<std::greater_equal>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if FMT_USE_CONSTEVAL
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
template <size_t N>
|
||||||
|
struct fixed_string {
|
||||||
|
char data[N] = {};
|
||||||
|
|
||||||
|
constexpr fixed_string(char const (&m)[N]) {
|
||||||
|
for (size_t i = 0; i != N; ++i) {
|
||||||
|
data[i] = m[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(string_view_test, from_constexpr_fixed_string) {
|
||||||
|
static constexpr auto fs = fixed_string<5>("x={}");
|
||||||
|
static constexpr auto fmt = fmt::string_view(fs.data);
|
||||||
|
EXPECT_EQ(fmt, "x={}");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
TEST(base_test, is_locking) {
|
TEST(base_test, is_locking) {
|
||||||
EXPECT_FALSE(fmt::detail::is_locking<const char(&)[3]>());
|
EXPECT_FALSE(fmt::detail::is_locking<const char(&)[3]>());
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user