use memchr for searching for '%' in printf format string
This commit is contained in:
parent
a30b279bad
commit
a2de072a58
@ -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;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user