diff --git a/src/fmt/fmt_test.go b/src/fmt/fmt_test.go index 9bec6f3f9e..e6239a51ba 100644 --- a/src/fmt/fmt_test.go +++ b/src/fmt/fmt_test.go @@ -1201,6 +1201,14 @@ func BenchmarkSprintfTruncateString(b *testing.B) { }) } +func BenchmarkSprintfSlowParsingPath(b *testing.B) { + b.RunParallel(func(pb *testing.PB) { + for pb.Next() { + Sprintf("%.v", nil) + } + }) +} + func BenchmarkSprintfQuoteString(b *testing.B) { b.RunParallel(func(pb *testing.PB) { for pb.Next() { diff --git a/src/fmt/print.go b/src/fmt/print.go index 2bd88f95a2..d1c99c1cd3 100644 --- a/src/fmt/print.go +++ b/src/fmt/print.go @@ -1067,8 +1067,11 @@ formatLoop: break } - verb, w := utf8.DecodeRuneInString(format[i:]) - i += w + verb, size := rune(format[i]), 1 + if verb >= utf8.RuneSelf { + verb, size = utf8.DecodeRuneInString(format[i:]) + } + i += size switch { case verb == '%': // Percent does not absorb operands and ignores f.wid and f.prec.