From 49f6771ca948c7e102cc8270daa2096872e45fb4 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Mon, 25 Apr 2016 08:24:14 -0700 Subject: [PATCH] Grow buffer --- fmt/time.h | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/fmt/time.h b/fmt/time.h index 7d815d3e..20e74dc2 100644 --- a/fmt/time.h +++ b/fmt/time.h @@ -42,14 +42,21 @@ void format(BasicFormatter &f, ++end; if (*end != '}') FMT_THROW(FormatError("missing '}' in format string")); - Buffer &buffer = f.writer().buffer(); - std::size_t start = buffer.size(); internal::MemoryBuffer format; format.append(format_str, end + 1); format[format.size() - 1] = '\0'; - std::size_t size = std::strftime(&buffer[start], buffer.capacity() - start, - &format[0], &tm); - buffer.resize(start + size); + Buffer &buffer = f.writer().buffer(); + std::size_t start = buffer.size(); + for (;;) { + std::size_t size = buffer.capacity() - start; + std::size_t count = std::strftime(&buffer[start], size, &format[0], &tm); + if (count != 0) { + buffer.resize(start + count); + break; + } + enum {MIN_GROWTH = 10}; + buffer.reserve(buffer.capacity() + size > MIN_GROWTH ? size : MIN_GROWTH); + } format_str = end + 1; } }