aboutsummaryrefslogtreecommitdiff
path: root/src/go/parser/interface.go
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2017-12-22 16:29:36 -0800
committerRobert Griesemer <gri@golang.org>2018-02-12 21:43:10 +0000
commit29461ccc7f7b6a73bc0104731cfbe0c2cbe86733 (patch)
tree6630247f2bc9bbbf31f7d452f223d8424de7823b /src/go/parser/interface.go
parentea012d100bad48e5659637fde2f4d9737a087815 (diff)
downloadgo-29461ccc7f7b6a73bc0104731cfbe0c2cbe86733.tar.gz
go-29461ccc7f7b6a73bc0104731cfbe0c2cbe86733.zip
go/parser: simplify code to read from an io.Reader (cleanup)
ioutil.ReadAll didn't exist when we wrote that parser code originally (in 2009). Now it does, so use it. This may also make that code path slightly more efficient. Also, now that we are guaranteed to have a fast path for reading from an io.Reader (and thus an io.ReadCloser), simplify setup code for parser.ParseFile calls in srcimporter.Importer.ParseFiles. Remove the associated TODO since we cannot reproduce any significant performance differences when running go test -run ImportStdLib for the case where we used to read directly from a file (even before the change to the parser). Fixes #19281. Change-Id: I816459d092bb9e27fdc85089b8f21d57ec3fd79a Reviewed-on: https://go-review.googlesource.com/85395 Reviewed-by: Alan Donovan <adonovan@google.com>
Diffstat (limited to 'src/go/parser/interface.go')
-rw-r--r--src/go/parser/interface.go6
1 files changed, 1 insertions, 5 deletions
diff --git a/src/go/parser/interface.go b/src/go/parser/interface.go
index 724d8658a7..9de160a798 100644
--- a/src/go/parser/interface.go
+++ b/src/go/parser/interface.go
@@ -35,11 +35,7 @@ func readSource(filename string, src interface{}) ([]byte, error) {
return s.Bytes(), nil
}
case io.Reader:
- var buf bytes.Buffer
- if _, err := io.Copy(&buf, s); err != nil {
- return nil, err
- }
- return buf.Bytes(), nil
+ return ioutil.ReadAll(s)
}
return nil, errors.New("invalid source")
}