]> Cypherpunks repositories - gostls13.git/commitdiff
fmt: add ascii fast path for decoding verbs
authorMartin Möhrmann <moehrmann@google.com>
Fri, 10 Mar 2017 19:55:51 +0000 (20:55 +0100)
committerMartin Möhrmann <moehrmann@google.com>
Mon, 14 Aug 2017 12:25:45 +0000 (12:25 +0000)
name                    old time/op  new time/op  delta
SprintfSlowParsingPath   108ns ± 4%   103ns ± 4%  -4.53%  (p=0.000 n=18+18)

Change-Id: I174463f303d1857e8d5b8a6283c025b3546e7b39
Reviewed-on: https://go-review.googlesource.com/44450
Run-TryBot: Martin Möhrmann <moehrmann@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
src/fmt/fmt_test.go
src/fmt/print.go

index 9bec6f3f9efe062eb26c36d2d9aa4bd5910bc615..e6239a51ba1fbb0ed4dd274eaf8140e1ec97ffc0 100644 (file)
@@ -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() {
index 2bd88f95a2b80a425e4df8cd35d2b0a77861620a..d1c99c1cd3e64c11603726f03c8b089e2421d58b 100644 (file)
@@ -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.