[Lldb-commits] [PATCH] D27459: Add a more succinct logging syntax

Daniel Colascione via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Tue Jan 17 11:03:42 PST 2017


dancol added inline comments.


================
Comment at: source/Core/Log.cpp:78
+  char *text;
+  vasprintf(&text, format, args);
+  message << text;
----------------
I usually implement printf-into-std::string by using `vsnprintf` to figure out how many characters we generate, using `std::string::resize` to create a buffer of that many characters (unfortunately, zero-filling them), then `vsnprintf` directly into that buffer. This way, you only need one allocation.

The currant approach involves at least three allocations: first, the string generated by `vasprintf`. Second, the internal `stringstream` buffer. Third, the copy of the buffer that `std::stringstream::str` generates.

It's more expensive that it needs to be.


https://reviews.llvm.org/D27459





More information about the lldb-commits mailing list