Skip to content

Commit 17f3171

Browse files
pmelkozerdrewdzzz
authored andcommitted
logger: make logger a bit faster
Eliminate copying from std::stringstream if complied with C++20 or higher
1 parent 8e009e8 commit 17f3171

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/Utils/Logger.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,11 @@ class Logger {
9090
std::stringstream strm;
9191
strm << log_lvl << ": ";
9292
(strm << ... << std::forward<ARGS>(args)) << '\n';
93-
std::string str = strm.str();
93+
/*
94+
* std::move is required to eliminate copying from
95+
* std::stringstream if complied with C++20 or higher.
96+
*/
97+
std::string str = std::move(strm).str();
9498
ssize_t rc = write(fd, std::data(str), std::size(str));
9599
(void)rc;
96100
}

0 commit comments

Comments
 (0)