use memchr for searching for '%' in printf format string (#1984)

This commit is contained in:
rimathia 2020-11-08 19:36:00 +01:00 committed by GitHub
parent 4c2d637203
commit 3302fd1088
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -474,8 +474,11 @@ OutputIt basic_printf_context<OutputIt, Char>::format() {
const Char* end = parse_ctx_.end(); const Char* end = parse_ctx_.end();
auto it = start; auto it = start;
while (it != end) { while (it != end) {
if (!detail::find<false, Char>(it, end, '%', it)) {
it = end; // detail::find leaves it == nullptr if it doesn't find '%'
break;
}
char_type c = *it++; char_type c = *it++;
if (c != '%') continue;
if (it != end && *it == c) { if (it != end && *it == c) {
out = std::copy(start, it, out); out = std::copy(start, it, out);
start = ++it; start = ++it;