1
0
mirror of https://github.com/golang/go synced 2024-11-18 22:04:43 -07:00

cmd/internal/bio: embed bufio.{Reader,Writer} in bio.{Reader,Writer}

Change-Id: Ie95b0b0d4f724f4769cf2d4f8063cb5019fa9bc9
Reviewed-on: https://go-review.googlesource.com/21781
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Dave Cheney 2016-04-08 20:37:54 +10:00
parent ca397bb68e
commit 93368be61e
4 changed files with 16 additions and 46 deletions

View File

@ -407,7 +407,7 @@ func dumpexport() {
pkgs = savedPkgs
pkgMap = savedPkgMap
} else {
size = export(bout.Writer(), Debug_export != 0)
size = export(bout.Writer, Debug_export != 0)
}
exportf("\n$$\n")
} else {

View File

@ -17,21 +17,15 @@ const EOF = -1
// Reader implements a seekable buffered io.Reader.
type Reader struct {
f *os.File
r *bufio.Reader
*bufio.Reader
}
// Writer implements a seekable buffered io.Writer.
type Writer struct {
f *os.File
w *bufio.Writer
*bufio.Writer
}
// Reader returns this Reader's underlying bufio.Reader.
func (r *Reader) Reader() *bufio.Reader { return r.r }
// Writer returns this Writer's underlying bufio.Writer.
func (w *Writer) Writer() *bufio.Writer { return w.w }
// Create creates the file named name and returns a Writer
// for that file.
func Create(name string) (*Writer, error) {
@ -39,7 +33,7 @@ func Create(name string) (*Writer, error) {
if err != nil {
return nil, err
}
return &Writer{f: f, w: bufio.NewWriter(f)}, nil
return &Writer{f: f, Writer: bufio.NewWriter(f)}, nil
}
// Open returns a Reader for the file named name.
@ -48,31 +42,23 @@ func Open(name string) (*Reader, error) {
if err != nil {
return nil, err
}
return &Reader{f: f, r: bufio.NewReader(f)}, nil
}
func (w *Writer) Write(p []byte) (int, error) {
return w.w.Write(p)
}
func (w *Writer) WriteString(p string) (int, error) {
return w.w.WriteString(p)
return &Reader{f: f, Reader: bufio.NewReader(f)}, nil
}
func (r *Reader) Seek(offset int64, whence int) int64 {
if whence == 1 {
offset -= int64(r.r.Buffered())
offset -= int64(r.Buffered())
}
off, err := r.f.Seek(offset, whence)
if err != nil {
log.Fatalf("seeking in output: %v", err)
}
r.r.Reset(r.f)
r.Reset(r.f)
return off
}
func (w *Writer) Seek(offset int64, whence int) int64 {
if err := w.w.Flush(); err != nil {
if err := w.Flush(); err != nil {
log.Fatalf("writing output: %v", err)
}
off, err := w.f.Seek(offset, whence)
@ -87,12 +73,12 @@ func (r *Reader) Offset() int64 {
if err != nil {
log.Fatalf("seeking in output [0, 1]: %v", err)
}
off -= int64(r.r.Buffered())
off -= int64(r.Buffered())
return off
}
func (w *Writer) Offset() int64 {
if err := w.w.Flush(); err != nil {
if err := w.Flush(); err != nil {
log.Fatalf("writing output: %v", err)
}
off, err := w.f.Seek(0, 1)
@ -102,16 +88,8 @@ func (w *Writer) Offset() int64 {
return off
}
func (w *Writer) Flush() error {
return w.w.Flush()
}
func (w *Writer) WriteByte(c byte) error {
return w.w.WriteByte(c)
}
func Bread(r *Reader, p []byte) int {
n, err := io.ReadFull(r.r, p)
n, err := io.ReadFull(r, p)
if n == 0 {
if err != nil && err != io.EOF {
n = -1
@ -121,7 +99,7 @@ func Bread(r *Reader, p []byte) int {
}
func Bgetc(r *Reader) int {
c, err := r.r.ReadByte()
c, err := r.ReadByte()
if err != nil {
if err != io.EOF {
log.Fatalf("reading input: %v", err)
@ -131,16 +109,8 @@ func Bgetc(r *Reader) int {
return int(c)
}
func (r *Reader) Read(p []byte) (int, error) {
return r.r.Read(p)
}
func (r *Reader) Peek(n int) ([]byte, error) {
return r.r.Peek(n)
}
func Brdline(r *Reader, delim int) string {
s, err := r.r.ReadBytes(byte(delim))
s, err := r.ReadBytes(byte(delim))
if err != nil {
log.Fatalf("reading input: %v", err)
}
@ -152,7 +122,7 @@ func (r *Reader) Close() error {
}
func (w *Writer) Close() error {
err := w.w.Flush()
err := w.Flush()
err1 := w.f.Close()
if err == nil {
err = err1

View File

@ -377,7 +377,7 @@ func (w *objWriter) writeLengths() {
func newObjWriter(ctxt *Link, b *bio.Writer) *objWriter {
return &objWriter{
ctxt: ctxt,
wr: b.Writer(),
wr: b.Writer,
vrefIdx: make(map[string]int),
refIdx: make(map[string]int),
}

View File

@ -150,7 +150,7 @@ type objReader struct {
func LoadObjFile(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) {
start := f.Offset()
r := &objReader{
rd: f.Reader(),
rd: f.Reader,
pkg: pkg,
ctxt: ctxt,
pn: pn,