From: Martin Möhrmann Date: Sat, 19 Mar 2016 12:18:43 +0000 (+0100) Subject: fmt: remove depth argument from handleMethods and printArg X-Git-Tag: go1.7beta1~1215 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=2f4d4206831b722070fecd7efcd0f1b122aa3760;p=gostls13.git fmt: remove depth argument from handleMethods and printArg handleMethods can format Error() and String() directly as its known these return strings that can be directly printed using fmtString. Remove the obsolete depth argument from handleMethods. Remove the depth argument from printArg since it is only ever called with depth set to 0. Recursion for formatting complex arguments is handled only by printValue which keeps track of depth. Change-Id: I4c4be588751de12ed999e7561a51bc168eb9eb2d Reviewed-on: https://go-review.googlesource.com/20911 Run-TryBot: Rob Pike TryBot-Result: Gobot Gobot Reviewed-by: Rob Pike --- diff --git a/src/fmt/print.go b/src/fmt/print.go index 71f4cabe53..bc244d9c81 100644 --- a/src/fmt/print.go +++ b/src/fmt/print.go @@ -317,7 +317,7 @@ func (p *pp) badVerb(verb rune) { case p.arg != nil: p.buf.WriteString(reflect.TypeOf(p.arg).String()) p.buf.WriteByte('=') - p.printArg(p.arg, 'v', 0) + p.printArg(p.arg, 'v') case p.value.IsValid(): p.buf.WriteString(p.value.Type().String()) p.buf.WriteByte('=') @@ -564,13 +564,13 @@ func (p *pp) catchPanic(arg interface{}, verb rune) { p.buf.WriteRune(verb) p.buf.WriteString(panicString) p.panicking = true - p.printArg(err, 'v', 0) + p.printArg(err, 'v') p.panicking = false p.buf.WriteByte(')') } } -func (p *pp) handleMethods(verb rune, depth int) (handled bool) { +func (p *pp) handleMethods(verb rune) (handled bool) { if p.erroring { return } @@ -605,13 +605,13 @@ func (p *pp) handleMethods(verb rune, depth int) (handled bool) { case error: handled = true defer p.catchPanic(p.arg, verb) - p.printArg(v.Error(), verb, depth) + p.fmtString(v.Error(), verb) return case Stringer: handled = true defer p.catchPanic(p.arg, verb) - p.printArg(v.String(), verb, depth) + p.fmtString(v.String(), verb) return } } @@ -619,7 +619,7 @@ func (p *pp) handleMethods(verb rune, depth int) (handled bool) { return false } -func (p *pp) printArg(arg interface{}, verb rune, depth int) { +func (p *pp) printArg(arg interface{}, verb rune) { p.arg = arg p.value = reflect.Value{} @@ -683,15 +683,15 @@ func (p *pp) printArg(arg interface{}, verb rune, depth int) { case []byte: p.fmtBytes(f, verb, bytesString) case reflect.Value: - p.printReflectValue(f, verb, depth) + p.printReflectValue(f, verb, 0) return default: // If the type is not simple, it might have methods. - if p.handleMethods(verb, depth) { + if p.handleMethods(verb) { return } // Need to use reflection - p.printReflectValue(reflect.ValueOf(arg), verb, depth) + p.printReflectValue(reflect.ValueOf(arg), verb, 0) return } p.arg = nil @@ -716,7 +716,7 @@ func (p *pp) printValue(value reflect.Value, verb rune, depth int) { if value.CanInterface() { p.arg = value.Interface() } - if p.handleMethods(verb, depth) { + if p.handleMethods(verb) { return } @@ -1110,7 +1110,7 @@ func (p *pp) doPrintf(format string, a []interface{}) { p.fmt.zero = false } - p.printArg(a[argNum], c, 0) + p.printArg(a[argNum], c) argNum++ } @@ -1129,7 +1129,7 @@ func (p *pp) doPrintf(format string, a []interface{}) { } else { p.buf.WriteString(reflect.TypeOf(arg).String()) p.buf.WriteByte('=') - p.printArg(arg, 'v', 0) + p.printArg(arg, 'v') } } p.buf.WriteByte(')') @@ -1146,7 +1146,7 @@ func (p *pp) doPrint(a []interface{}, addspace, addnewline bool) { if argNum > 0 && (addspace || (!isString && !prevString)) { p.buf.WriteByte(' ') } - p.printArg(arg, 'v', 0) + p.printArg(arg, 'v') prevString = isString } if addnewline {