From 2aa2526f642fd629e74cbbc4cadb1e168d304d53 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Tue, 19 May 2020 10:54:22 -0700 Subject: [PATCH] Optimize small string concatenation --- include/fmt/format.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index 257420bdc49c..30de8ec46ffa 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -2513,7 +2513,12 @@ FMT_CONSTEXPR void parse_format_string(basic_string_view format_str, Handler&& handler) { struct writer { FMT_CONSTEXPR void operator()(const Char* begin, const Char* end) { - if (begin == end) return; + if (begin + 1 >= end) { + if (begin == end) return; + if (*begin == '}') + return handler_.on_error("unmatched '}' in format string"); + return handler_.on_text(begin, begin + 1); + } for (;;) { const Char* p = nullptr; if (!find(begin, end, '}', p))