]> Cypherpunks repositories - gostls13.git/commitdiff
fmt: cleanup %p and %T code paths
authorMartin Möhrmann <martisch@uos.de>
Sat, 12 Mar 2016 12:53:19 +0000 (13:53 +0100)
committerRob Pike <r@golang.org>
Wed, 16 Mar 2016 05:13:10 +0000 (05:13 +0000)
Remove check for %p and %T in printValue.
These verbs are not recursive and are handled already in
printArg which is called on any argument before printValue.

Format the type string for %T directly instead of invoking
the more complex printArg with %s on the type string.

Decouple the %T tests from variables declared in scan_test.go.

Change-Id: Ibd51566bd4cc1a260ce6d052f36382ed05020b48
Reviewed-on: https://go-review.googlesource.com/20622
Run-TryBot: Rob Pike <r@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
src/fmt/fmt_test.go
src/fmt/print.go

index 8ff53cf48705a424a9dd74e8f2b4a12740ba5f65..c2ca690a84b68ba6dff3cd36d582240c3d36d1d2 100644 (file)
@@ -723,10 +723,12 @@ var fmtTests = []struct {
        {"%#v", S{F(7), G(8)}, "fmt_test.S{F:<v=F(7)>, G:GoString(8)}"},
 
        // %T
+       {"%T", byte(0), "uint8"},
+       {"%T", reflect.ValueOf(nil), "reflect.Value"},
        {"%T", (4 - 3i), "complex128"},
        {"%T", renamedComplex128(4 - 3i), "fmt_test.renamedComplex128"},
-       {"%T", intVal, "int"},
-       {"%6T", &intVal, "  *int"},
+       {"%T", intVar, "int"},
+       {"%6T", &intVar, "  *int"},
        {"%10T", nil, "     <nil>"},
        {"%-10T", nil, "<nil>     "},
 
index e9876913b04a0a7c6f778eeef27742706bf7fd3b..a077f359165f6ce112af7d750bbecfb6f6d38f76 100644 (file)
@@ -700,10 +700,10 @@ func (p *pp) printArg(arg interface{}, verb rune, depth int) {
        // %T (the value's type) and %p (its address) are special; we always do them first.
        switch verb {
        case 'T':
-               p.printArg(reflect.TypeOf(arg).String(), 's', 0)
+               p.fmt.fmt_s(reflect.TypeOf(arg).String())
                return
        case 'p':
-               p.fmtPointer(reflect.ValueOf(arg), verb)
+               p.fmtPointer(reflect.ValueOf(arg), 'p')
                return
        }
 
@@ -760,11 +760,12 @@ func (p *pp) printArg(arg interface{}, verb rune, depth int) {
        p.arg = nil
 }
 
-// printValue is like printArg but starts with a reflect value, not an interface{} value.
+// printValue is similar to printArg but starts with a reflect value, not an interface{} value.
+// It does not handle 'p' and 'T' verbs because these should have been already handled by printArg.
 func (p *pp) printValue(value reflect.Value, verb rune, depth int) {
        if !value.IsValid() {
                switch verb {
-               case 'T', 'v':
+               case 'v':
                        p.buf.WriteString(nilAngleString)
                default:
                        p.badVerb(verb)
@@ -772,17 +773,6 @@ func (p *pp) printValue(value reflect.Value, verb rune, depth int) {
                return
        }
 
-       // Special processing considerations.
-       // %T (the value's type) and %p (its address) are special; we always do them first.
-       switch verb {
-       case 'T':
-               p.printArg(value.Type().String(), 's', 0)
-               return
-       case 'p':
-               p.fmtPointer(value, verb)
-               return
-       }
-
        // Handle values with special methods.
        // Call always, even when arg == nil, because handleMethods clears p.fmt.plus for us.
        p.arg = nil // Make sure it's cleared, for safety.