ImGuiTextBuffer: Avoid heap allocation when empty.

This commit is contained in:
omar
2018-10-10 17:02:14 +02:00
parent 1efafa1d29
commit d02b11dfbd
3 changed files with 18 additions and 12 deletions

View File

@ -1956,6 +1956,8 @@ bool ImGuiTextFilter::PassFilter(const char* text, const char* text_end) const
#endif
#endif
char ImGuiTextBuffer::EmptyString[1] = { 0 };
// Helper: Text buffer for logging/accumulating text
void ImGuiTextBuffer::appendfv(const char* fmt, va_list args)
{
@ -1969,7 +1971,8 @@ void ImGuiTextBuffer::appendfv(const char* fmt, va_list args)
return;
}
const int write_off = Buf.Size;
// Add zero-terminator the first time
const int write_off = (Buf.Size != 0) ? Buf.Size : 1;
const int needed_sz = write_off + len;
if (write_off + len >= Buf.Capacity)
{