Skip to content

Commit c8f4af0

Browse files
committed
Remove the last uses of _format()
Three of the four cases are simple, we can use fmt::format and don't need to parse a format string. The last case has the format string R"(\u{:04x})" to parse, but that's only needed when some control characters are written out in JSON format, which doesn't happen that often. Fixes #1704
1 parent efb0072 commit c8f4af0

3 files changed

Lines changed: 6 additions & 8 deletions

File tree

src/format.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515

1616
#include <stdexcept>
1717

18-
// NOLINTNEXTLINE(google-global-names-in-headers,google-build-using-namespace)
19-
using namespace fmt::literals;
20-
2118
template <typename S, typename... TArgs>
2219
std::runtime_error fmt_error(S const &format_str, TArgs &&...args)
2320
{

src/json-writer.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class json_writer_t
3030
void number(T value)
3131
{
3232
if (std::isfinite(value)) {
33-
fmt::format_to(std::back_inserter(m_buffer), "{}"_format(value));
33+
m_buffer += fmt::to_string(value);
3434
} else {
3535
null();
3636
}
@@ -39,7 +39,7 @@ class json_writer_t
3939
template <typename T, std::enable_if_t<std::is_integral_v<T>, bool> = true>
4040
void number(T value)
4141
{
42-
fmt::format_to(std::back_inserter(m_buffer), "{}"_format(value));
42+
m_buffer += fmt::to_string(value);
4343
}
4444

4545
void string(char const *str)
@@ -70,8 +70,8 @@ class json_writer_t
7070
break;
7171
default:
7272
if (c <= 0x1f) {
73-
m_buffer.append(
74-
R"(\u{:04x})"_format(static_cast<unsigned char>(c)));
73+
m_buffer.append(fmt::format(R"(\u{:04x})",
74+
static_cast<unsigned char>(c)));
7575
} else {
7676
m_buffer += c;
7777
}

src/pgsql.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ struct exec_arg
138138
constexpr static std::size_t const buffers_needed = 1;
139139
static char const *to_str(std::vector<std::string> *data, T param)
140140
{
141-
return data->emplace_back("{}"_format(std::forward<T>(param))).c_str();
141+
return data->emplace_back(fmt::to_string(std::forward<T>(param)))
142+
.c_str();
142143
}
143144
};
144145

0 commit comments

Comments
 (0)