mirror of
https://github.com/golang/go.git
synced 2025-05-16 04:44:39 +00:00
cmd/link: batch writing of bytes
In best of 10, linking cmd/go shows a ~10% improvement. tip: real 0m1.152s user 0m1.005s this: real 0m1.065s user 0m0.924s Change-Id: I303a20b94332feaedc1033c453247a0e4c05c843 Reviewed-on: https://go-review.googlesource.com/19978 Reviewed-by: David Crawshaw <crawshaw@golang.org>
This commit is contained in:
parent
07ccc21295
commit
d3b00a8cc4
@ -708,7 +708,6 @@ func blk(start *LSym, addr int64, size int64) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
eaddr := addr + size
|
eaddr := addr + size
|
||||||
var ep []byte
|
|
||||||
var p []byte
|
var p []byte
|
||||||
for ; sym != nil; sym = sym.Next {
|
for ; sym != nil; sym = sym.Next {
|
||||||
if sym.Type&obj.SSUB != 0 {
|
if sym.Type&obj.SSUB != 0 {
|
||||||
@ -723,18 +722,16 @@ func blk(start *LSym, addr int64, size int64) {
|
|||||||
errorexit()
|
errorexit()
|
||||||
}
|
}
|
||||||
|
|
||||||
for ; addr < sym.Value; addr++ {
|
if addr < sym.Value {
|
||||||
Cput(0)
|
strnput("", int(sym.Value-addr))
|
||||||
|
addr = sym.Value
|
||||||
}
|
}
|
||||||
p = sym.P
|
p = sym.P
|
||||||
ep = p[len(sym.P):]
|
Cwrite(p)
|
||||||
for -cap(p) < -cap(ep) {
|
|
||||||
Cput(uint8(p[0]))
|
|
||||||
p = p[1:]
|
|
||||||
}
|
|
||||||
addr += int64(len(sym.P))
|
addr += int64(len(sym.P))
|
||||||
for ; addr < sym.Value+sym.Size; addr++ {
|
if addr < sym.Value+sym.Size {
|
||||||
Cput(0)
|
strnput("", int(sym.Value+sym.Size-addr))
|
||||||
|
addr = sym.Value + sym.Size
|
||||||
}
|
}
|
||||||
if addr != sym.Value+sym.Size {
|
if addr != sym.Value+sym.Size {
|
||||||
Diag("phase error: addr=%#x value+size=%#x", int64(addr), int64(sym.Value)+sym.Size)
|
Diag("phase error: addr=%#x value+size=%#x", int64(addr), int64(sym.Value)+sym.Size)
|
||||||
@ -746,8 +743,8 @@ func blk(start *LSym, addr int64, size int64) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for ; addr < eaddr; addr++ {
|
if addr < eaddr {
|
||||||
Cput(0)
|
strnput("", int(eaddr-addr))
|
||||||
}
|
}
|
||||||
Cflush()
|
Cflush()
|
||||||
}
|
}
|
||||||
@ -899,15 +896,26 @@ func Datblk(addr int64, size int64) {
|
|||||||
fmt.Fprintf(&Bso, "\t%.8x|\n", uint(eaddr))
|
fmt.Fprintf(&Bso, "\t%.8x|\n", uint(eaddr))
|
||||||
}
|
}
|
||||||
|
|
||||||
func strnput(s string, n int) {
|
var zeros [512]byte
|
||||||
for ; n > 0 && s != ""; s = s[1:] {
|
|
||||||
Cput(uint8(s[0]))
|
|
||||||
n--
|
|
||||||
}
|
|
||||||
|
|
||||||
for n > 0 {
|
// strnput writes the first n bytes of s.
|
||||||
Cput(0)
|
// If n is larger then len(s),
|
||||||
n--
|
// it is padded with NUL bytes.
|
||||||
|
func strnput(s string, n int) {
|
||||||
|
if len(s) >= n {
|
||||||
|
Cwritestring(s[:n])
|
||||||
|
} else {
|
||||||
|
Cwritestring(s)
|
||||||
|
n -= len(s)
|
||||||
|
for n > 0 {
|
||||||
|
if len(zeros) >= n {
|
||||||
|
Cwrite(zeros[:n])
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
Cwrite(zeros[:])
|
||||||
|
n -= len(zeros)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1850,6 +1850,10 @@ func Cseek(p int64) {
|
|||||||
coutbuf.off = p
|
coutbuf.off = p
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Cwritestring(s string) {
|
||||||
|
coutbuf.WriteString(s)
|
||||||
|
}
|
||||||
|
|
||||||
func Cwrite(p []byte) {
|
func Cwrite(p []byte) {
|
||||||
coutbuf.Write(p)
|
coutbuf.Write(p)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user