1
0
mirror of https://github.com/golang/go synced 2024-11-23 21:40:05 -07:00

cmd/internal/ld: remove Biobuf unget

The underlying *bufio.Reader does everything that's needed here.

Change-Id: If0712a5b4d3142ae4bceaa2efe287eaf2b91e54e
Reviewed-on: https://go-review.googlesource.com/9365
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
David Crawshaw 2015-04-27 12:53:34 -04:00
parent cbbe9f63dc
commit 05d53165ce
2 changed files with 11 additions and 42 deletions

View File

@ -41,9 +41,11 @@ func ldobjfile(ctxt *Link, f *Biobuf, pkg string, length int64, pn string) {
}
for {
c = Bgetc(f)
Bungetc(f)
if c == 0xff {
c, err := f.r.Peek(1)
if err != nil {
log.Fatalf("%s: peeking: %v", pn, err)
}
if c[0] == 0xff {
break
}
readsym(ctxt, f, pkg, pn)

View File

@ -77,8 +77,6 @@ func cutStringAtNUL(s string) string {
}
type Biobuf struct {
unget [2]int
numUnget int
f *os.File
r *bufio.Reader
w *bufio.Writer
@ -164,10 +162,6 @@ func Bputc(b *Biobuf, c byte) {
const Beof = -1
func Bread(b *Biobuf, p []byte) int {
if b.numUnget > 0 {
Bseek(b, -int64(b.numUnget), 1)
b.numUnget = 0
}
n, err := io.ReadFull(b.r, p)
if n == 0 {
if err != nil && err != io.EOF {
@ -178,25 +172,14 @@ func Bread(b *Biobuf, p []byte) int {
}
func Bgetc(b *Biobuf) int {
if b.numUnget > 0 {
b.numUnget--
return int(b.unget[b.numUnget])
}
c, err := b.r.ReadByte()
r := int(c)
if err != nil {
r = -1
return -1
}
b.unget[1] = b.unget[0]
b.unget[0] = r
return r
return int(c)
}
func Bgetrune(b *Biobuf) int {
if b.numUnget > 0 {
Bseek(b, -int64(b.numUnget), 1)
b.numUnget = 0
}
r, _, err := b.r.ReadRune()
if err != nil {
return -1
@ -204,19 +187,11 @@ func Bgetrune(b *Biobuf) int {
return int(r)
}
func Bungetrune(b *Biobuf) {
b.r.UnreadRune()
}
func (b *Biobuf) Read(p []byte) (int, error) {
return b.r.Read(p)
}
func Brdline(b *Biobuf, delim int) string {
if b.numUnget > 0 {
Bseek(b, -int64(b.numUnget), 1)
b.numUnget = 0
}
s, err := b.r.ReadBytes(byte(delim))
if err != nil {
log.Fatalf("reading input: %v", err)
@ -226,10 +201,6 @@ func Brdline(b *Biobuf, delim int) string {
}
func Brdstr(b *Biobuf, delim int, cut int) string {
if b.numUnget > 0 {
Bseek(b, -int64(b.numUnget), 1)
b.numUnget = 0
}
s, err := b.r.ReadString(byte(delim))
if err != nil {
log.Fatalf("reading input: %v", err)
@ -255,10 +226,6 @@ func Blinelen(b *Biobuf) int {
return b.linelen
}
func Bungetc(b *Biobuf) {
b.numUnget++
}
func Bflush(b *Biobuf) error {
return b.w.Flush()
}