Skip to content

Commit a03321c

Browse files
committed
perf(io): streamline print rendering
1 parent b29b363 commit a03321c

5 files changed

Lines changed: 610 additions & 2086 deletions

File tree

‎include/vix/console/Console.hpp‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -796,8 +796,9 @@ namespace vix
796796
{
797797
using U = std::remove_cvref_t<T>;
798798

799-
if constexpr (vix::traits::has_formatter_v<U> ||
800-
vix::traits::has_vix_format_v<U>)
799+
if constexpr (vix::detail::has_formatter_v<U> ||
800+
vix::detail::context_adl_formattable<U> ||
801+
vix::detail::legacy_adl_formattable<U>)
801802
{
802803
std::ostringstream stream;
803804

@@ -811,8 +812,7 @@ namespace vix
811812
print_config_value.compact = true;
812813
print_config_value.raw_strings = true;
813814

814-
scoped_config guard{print_config_value};
815-
vix::write_to(stream, value);
815+
vix::write_to(stream, value, print_config_value);
816816

817817
std::string rendered = stream.str();
818818
truncate_record_(rendered, limits.max_record_size);
@@ -835,7 +835,7 @@ namespace vix
835835
// A formatter<T> or ADL vix_format hook belongs to the print engine.
836836
// If inspect cannot render any nested part, retry the entire value using
837837
// print so existing formatter extensions remain compatible.
838-
if (rendered.find("<unprintable:") != std::string::npos)
838+
if (rendered.find("<unprintable") != std::string::npos)
839839
{
840840
std::ostringstream stream;
841841

@@ -849,8 +849,7 @@ namespace vix
849849
print_config_value.compact = true;
850850
print_config_value.raw_strings = true;
851851

852-
scoped_config guard{print_config_value};
853-
vix::write_to(stream, value);
852+
vix::write_to(stream, value, print_config_value);
854853
rendered = stream.str();
855854
}
856855

‎include/vix/format/Format.hpp‎

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -86,22 +86,11 @@ namespace vix
8686
[[nodiscard]] inline std::string format_arg_to_string(const T &value)
8787
{
8888
std::ostringstream oss;
89-
90-
auto &cfg = vix::default_config();
91-
const bool old_raw_strings = cfg.raw_strings;
89+
print_config cfg = default_config();
90+
cfg.out = &oss;
91+
cfg.end.clear();
9292
cfg.raw_strings = false;
93-
94-
try
95-
{
96-
vix::detail::write(oss, value);
97-
}
98-
catch (...)
99-
{
100-
cfg.raw_strings = old_raw_strings;
101-
throw;
102-
}
103-
104-
cfg.raw_strings = old_raw_strings;
93+
vix::write_to(oss, value, cfg);
10594
return oss.str();
10695
}
10796

‎include/vix/meta/traits.hpp‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,13 @@
4444
#define VIX_HAS_EXPECTED 0
4545
#endif
4646

47+
#include <vix/print/Formatter.hpp>
48+
4749
namespace vix
4850
{
4951
// Forward declarations for extension-point detection.
5052
struct inspect_context;
5153

52-
template <typename T, typename = void>
53-
struct formatter;
54-
5554
template <typename T, typename = void>
5655
struct inspector;
5756

‎include/vix/print/Formatter.hpp‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/** @file Formatter.hpp Shared declaration of the vix::print extension point. */
2+
#ifndef VIX_PRINT_FORMATTER_HPP
3+
#define VIX_PRINT_FORMATTER_HPP
4+
5+
namespace vix
6+
{
7+
/** Specialize formatter<T> to render T through the legacy ostream hook. */
8+
template <typename T, typename = void>
9+
struct formatter
10+
{
11+
};
12+
}
13+
14+
#endif

0 commit comments

Comments
 (0)