From 3302fd108858cec8bf70fb56a14145775a6d3861 Mon Sep 17 00:00:00 2001 From: rimathia Date: Sun, 8 Nov 2020 19:36:00 +0100 Subject: [PATCH] use memchr for searching for '%' in printf format string (#1984) --- include/fmt/printf.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/include/fmt/printf.h b/include/fmt/printf.h index 8c28ac23..b44afaba 100644 --- a/include/fmt/printf.h +++ b/include/fmt/printf.h @@ -474,8 +474,11 @@ OutputIt basic_printf_context::format() { const Char* end = parse_ctx_.end(); auto it = start; while (it != end) { + if (!detail::find(it, end, '%', it)) { + it = end; // detail::find leaves it == nullptr if it doesn't find '%' + break; + } char_type c = *it++; - if (c != '%') continue; if (it != end && *it == c) { out = std::copy(start, it, out); start = ++it;