use memchr for finding '%' in formatting string in printf.h

This commit is contained in:
rimathia 2020-09-03 11:47:02 +02:00
parent 6cccdc24bc
commit 1860f37169

View File

@ -474,8 +474,18 @@ 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 (end - it < 32) {
// Use a simple linear search instead of memchr for small strings.
it = std::find(it, end, '%');
} else {
if (!detail::find<false, Char>(it, end, '%', it)) {
it = end;
}
}
if (it == end) {
continue;
}
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;