Commit 32c39fa1 authored by Russ Cox's avatar Russ Cox

go/printer: avoid reflect in print

R=gri
CC=golang-dev
https://golang.org/cl/704041
parent 29f1ca52
...@@ -739,16 +739,13 @@ func (p *printer) writeWhitespace(n int) { ...@@ -739,16 +739,13 @@ func (p *printer) writeWhitespace(n int) {
// space for best comment placement. Then, any leftover whitespace is // space for best comment placement. Then, any leftover whitespace is
// printed, followed by the actual token. // printed, followed by the actual token.
// //
func (p *printer) print(args ...) { func (p *printer) print(args ...interface{}) {
v := reflect.NewValue(args).(*reflect.StructValue) for _, f := range args {
for i := 0; i < v.NumField(); i++ {
f := v.Field(i)
next := p.pos // estimated position of next item next := p.pos // estimated position of next item
var data []byte var data []byte
var tag HTMLTag var tag HTMLTag
isKeyword := false isKeyword := false
switch x := f.Interface().(type) { switch x := f.(type) {
case whiteSpace: case whiteSpace:
if x == ignore { if x == ignore {
// don't add ignore's to the buffer; they // don't add ignore's to the buffer; they
...@@ -795,7 +792,8 @@ func (p *printer) print(args ...) { ...@@ -795,7 +792,8 @@ func (p *printer) print(args ...) {
next = x // accurate position of next item next = x // accurate position of next item
} }
default: default:
panicln("print: unsupported argument type", f.Type().String()) fmt.Fprintf(os.Stderr, "print: unsupported argument type %T\n", f)
panic()
} }
p.pos = next p.pos = next
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment