1
0
mirror of https://github.com/golang/go synced 2024-11-24 15:30:13 -07:00

cmd/link: track offset instead of using seek

The Cpos function is used frequently (at least once per symbol) and
it is implemented with the seek syscall. Instead, track current
output offset and use it.

Building the godoc binary with DWARF, best of ten:

tip:  real 0m1.287s user 0m1.573s
this: real 0m1.208s user 0m1.555s

Change-Id: I068148695cd6b4d32cd145db25e59e6f6bae6945
Reviewed-on: https://go-review.googlesource.com/20055
Run-TryBot: David Crawshaw <crawshaw@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
David Crawshaw 2016-02-29 08:00:46 -09:00
parent ed1a5e5da6
commit 6d0b551931

View File

@ -250,11 +250,26 @@ var (
Bso obj.Biobuf
)
var coutbuf struct {
*bufio.Writer
f *os.File
type outBuf struct {
w *bufio.Writer
f *os.File
off int64
}
func (w *outBuf) Write(p []byte) (n int, err error) {
n, err = w.w.Write(p)
w.off += int64(n)
return n, err
}
func (w *outBuf) WriteString(s string) (n int, err error) {
n, err = coutbuf.w.WriteString(s)
w.off += int64(n)
return n, err
}
var coutbuf outBuf
const pkgname = "__.PKGDEF"
var (
@ -396,7 +411,7 @@ func libinit() {
Exitf("cannot create %s: %v", outfile, err)
}
coutbuf.Writer = bufio.NewWriter(f)
coutbuf.w = bufio.NewWriter(f)
coutbuf.f = f
if INITENTRY == "" {
@ -759,9 +774,7 @@ func objfile(lib *Library) {
fmt.Fprintf(&Bso, "%5.2f ldobj: %s (%s)\n", obj.Cputime(), lib.File, pkg)
}
Bso.Flush()
var err error
var f *obj.Biobuf
f, err = obj.Bopenr(lib.File)
f, err := obj.Bopenr(lib.File)
if err != nil {
Exitf("cannot open file %s: %v", lib.File, err)
}
@ -953,7 +966,7 @@ func hostlinksetup() {
Exitf("cannot create %s: %v", p, err)
}
coutbuf.Writer = bufio.NewWriter(f)
coutbuf.w = bufio.NewWriter(f)
coutbuf.f = f
}
@ -1817,24 +1830,24 @@ func stkprint(ch *Chain, limit int) {
}
func Cflush() {
if err := coutbuf.Writer.Flush(); err != nil {
if err := coutbuf.w.Flush(); err != nil {
Exitf("flushing %s: %v", coutbuf.f.Name(), err)
}
}
func Cpos() int64 {
off, err := coutbuf.f.Seek(0, 1)
if err != nil {
Exitf("seeking in output [0, 1]: %v", err)
}
return off + int64(coutbuf.Buffered())
return coutbuf.off
}
func Cseek(p int64) {
if p == coutbuf.off {
return
}
Cflush()
if _, err := coutbuf.f.Seek(p, 0); err != nil {
Exitf("seeking in output [0, 1]: %v", err)
}
coutbuf.off = p
}
func Cwrite(p []byte) {
@ -1842,7 +1855,8 @@ func Cwrite(p []byte) {
}
func Cput(c uint8) {
coutbuf.WriteByte(c)
coutbuf.w.WriteByte(c)
coutbuf.off++
}
func usage() {