Skip to content

Commit 8d3f731

Browse files
authored
Mark static arrays as constexpr for binary opt (#4680)
1 parent dc97113 commit 8d3f731

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

include/fmt/format-inl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ FMT_FUNC void format_error_code(detail::buffer<char>& out, int error_code,
9292
// Report error code making sure that the output fits into inline_buffer_size
9393
// to avoid dynamic memory allocation and potential bad_alloc.
9494
out.try_resize(0);
95-
static const char SEP[] = ": ";
96-
static const char ERROR_STR[] = "error ";
95+
static constexpr char SEP[] = ": ";
96+
static constexpr char ERROR_STR[] = "error ";
9797
// Subtract 2 to account for terminating null characters in SEP and ERROR_STR.
9898
size_t error_code_size = sizeof(SEP) + sizeof(ERROR_STR) - 2;
9999
auto abs_value = static_cast<uint32_or_64_or_128_t<int>>(error_code);

include/fmt/format.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,7 +1071,7 @@ using uint64_or_128_t = conditional_t<num_bits<T>() <= 64, uint64_t, uint128_t>;
10711071
inline auto digits2(size_t value) noexcept -> const char* {
10721072
// Align data since unaligned access may be slower when crossing a
10731073
// hardware-specific boundary.
1074-
alignas(2) static const char data[] =
1074+
alignas(2) static constexpr char data[] =
10751075
"0001020304050607080910111213141516171819"
10761076
"2021222324252627282930313233343536373839"
10771077
"4041424344454647484950515253545556575859"
@@ -1084,7 +1084,7 @@ inline auto digits2(size_t value) noexcept -> const char* {
10841084
// the decimal point of i / 100 in base 2, the first 2 bytes
10851085
// after digits2_i(x) is the string representation of i.
10861086
inline auto digits2_i(size_t value) noexcept -> const char* {
1087-
alignas(2) static const char data[] =
1087+
alignas(2) static constexpr char data[] =
10881088
"00010203 0405060707080910 1112"
10891089
"131414151617 18192021 222324 "
10901090
"25262728 2930313232333435 3637"

0 commit comments

Comments
 (0)