Commit 6ecaae03 authored by Than McIntosh's avatar Than McIntosh

[dev.link] cmd/link: remove unused slow paths from BytesAt/StringAt

This change removes the NewReader function (no longer used by objdump)
and prunes away the now unused code paths from Reader.BytesAt and
Reader.StringAt, which helps with performance. At the moment the
reader operates by always ingesting the entire object file (either via
direct read or by mmap), meaning that there will always be a slice
available for us to index into.

Change-Id: I3af7396effe19e50ed594fe8d82fd2d15465687c
Reviewed-on: https://go-review.googlesource.com/c/go/+/201437
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarCherry Zhang <cherryyz@google.com>
Reviewed-by: default avatarJeremy Faller <jeremy@golang.org>
parent e5acb58c
......@@ -396,15 +396,6 @@ type Reader struct {
h Header // keep block offsets
}
func NewReader(rd io.ReaderAt, off uint32) *Reader {
r := &Reader{rd: rd, start: off}
err := r.h.Read(r)
if err != nil {
return nil
}
return r
}
func NewReaderFromBytes(b []byte, readonly bool) *Reader {
r := &Reader{b: b, readonly: readonly, rd: bytes.NewReader(b), start: 0}
err := r.h.Read(r)
......@@ -418,16 +409,8 @@ func (r *Reader) BytesAt(off uint32, len int) []byte {
if len == 0 {
return nil
}
if r.b != nil {
end := int(off) + len
return r.b[int(off):end:end]
}
b := make([]byte, len)
_, err := r.rd.ReadAt(b, int64(r.start+off))
if err != nil {
panic("corrupted input")
}
return b
end := int(off) + len
return r.b[int(off):end:end]
}
func (r *Reader) uint64At(off uint32) uint64 {
......@@ -460,17 +443,9 @@ func (r *Reader) uint8At(off uint32) uint8 {
func (r *Reader) StringAt(off uint32) string {
l := r.uint32At(off)
if r.b != nil {
b := r.b[off+4 : off+4+l]
if r.readonly {
return toString(b) // backed by RO memory, ok to make unsafe string
}
return string(b)
}
b := make([]byte, l)
n, err := r.rd.ReadAt(b, int64(r.start+off+4))
if n != int(l) || err != nil {
panic("corrupted input")
b := r.b[off+4 : off+4+l]
if r.readonly {
return toString(b) // backed by RO memory, ok to make unsafe string
}
return string(b)
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment