From: Robert Griesemer Date: Fri, 4 Feb 2011 23:36:32 +0000 (-0800) Subject: gofmt: no need for lexical compare of src and res (optimization) X-Git-Tag: weekly.2011-02-15~88 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=eeafc06538bd137bab71c745e94c1219d99134ab;p=gostls13.git gofmt: no need for lexical compare of src and res (optimization) R=r CC=golang-dev https://golang.org/cl/4130046 --- diff --git a/src/cmd/gofmt/gofmt.go b/src/cmd/gofmt/gofmt.go index d7b70c4615..1eb4a95c0e 100644 --- a/src/cmd/gofmt/gofmt.go +++ b/src/cmd/gofmt/gofmt.go @@ -113,19 +113,20 @@ func processFile(f *os.File) os.Error { simplify(file) } - var res bytes.Buffer - _, err = (&printer.Config{printerMode, *tabWidth, nil}).Fprint(&res, fset, file) + var buf bytes.Buffer + _, err = (&printer.Config{printerMode, *tabWidth, nil}).Fprint(&buf, fset, file) if err != nil { return err } + res := buf.Bytes() - if bytes.Compare(src, res.Bytes()) != 0 { + if !bytes.Equal(src, res) { // formatting has changed if *list { fmt.Fprintln(os.Stdout, f.Name()) } if *write { - err = ioutil.WriteFile(f.Name(), res.Bytes(), 0) + err = ioutil.WriteFile(f.Name(), res, 0) if err != nil { return err } @@ -133,7 +134,7 @@ func processFile(f *os.File) os.Error { } if !*list && !*write { - _, err = os.Stdout.Write(res.Bytes()) + _, err = os.Stdout.Write(res) } return err