mirror of
https://github.com/Xahau/xahaud.git
synced 2025-11-20 10:35:50 +00:00
Compare commits
2 Commits
dev
...
nd-preserv
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9753692a9a | ||
|
|
70942e5882 |
@@ -360,6 +360,7 @@ Logs::format(
|
|||||||
if (!partition.empty())
|
if (!partition.empty())
|
||||||
{
|
{
|
||||||
#ifdef BEAST_ENHANCED_LOGGING
|
#ifdef BEAST_ENHANCED_LOGGING
|
||||||
|
if (beast::detail::should_log_use_colors())
|
||||||
output += beast::detail::get_log_highlight_color();
|
output += beast::detail::get_log_highlight_color();
|
||||||
#endif
|
#endif
|
||||||
output += partition + ":";
|
output += partition + ":";
|
||||||
@@ -392,6 +393,7 @@ Logs::format(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef BEAST_ENHANCED_LOGGING
|
#ifdef BEAST_ENHANCED_LOGGING
|
||||||
|
if (beast::detail::should_log_use_colors())
|
||||||
output += "\033[0m";
|
output += "\033[0m";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -155,14 +155,43 @@ Journal::ScopedStream::~ScopedStream()
|
|||||||
|
|
||||||
#ifdef BEAST_ENHANCED_LOGGING
|
#ifdef BEAST_ENHANCED_LOGGING
|
||||||
// Add suffix if location is enabled
|
// Add suffix if location is enabled
|
||||||
if (file_ && detail::should_show_location() && !s.empty() && s != "\n")
|
if (file_ && detail::should_show_location() && !s.empty())
|
||||||
{
|
{
|
||||||
std::ostringstream combined;
|
// Single optimized scan from the end
|
||||||
combined << s;
|
size_t const lastNonWhitespace = s.find_last_not_of(" \n\r\t");
|
||||||
if (!s.empty() && s.back() != ' ')
|
|
||||||
combined << " ";
|
// Skip if message is only whitespace (e.g., just "\n" or " \n\n")
|
||||||
detail::log_write_location_string(combined, file_, line_);
|
if (lastNonWhitespace != std::string::npos)
|
||||||
s = combined.str();
|
{
|
||||||
|
// Count only the trailing newlines (tiny range)
|
||||||
|
size_t trailingNewlines = 0;
|
||||||
|
for (size_t i = lastNonWhitespace + 1; i < s.length(); ++i)
|
||||||
|
{
|
||||||
|
if (s[i] == '\n')
|
||||||
|
++trailingNewlines;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build location string once
|
||||||
|
std::ostringstream locStream;
|
||||||
|
detail::log_write_location_string(locStream, file_, line_);
|
||||||
|
std::string const location = locStream.str();
|
||||||
|
|
||||||
|
// Pre-allocate exact size → zero reallocations
|
||||||
|
size_t const finalSize = lastNonWhitespace + 1 + 1 +
|
||||||
|
location.length() + trailingNewlines;
|
||||||
|
|
||||||
|
std::string result;
|
||||||
|
result.reserve(finalSize);
|
||||||
|
|
||||||
|
// Direct string ops (no ostringstream overhead)
|
||||||
|
result.append(s, 0, lastNonWhitespace + 1);
|
||||||
|
result.push_back(' ');
|
||||||
|
result += location;
|
||||||
|
if (trailingNewlines > 0)
|
||||||
|
result.append(trailingNewlines, '\n');
|
||||||
|
|
||||||
|
s = std::move(result); // Move, no copy
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user