mirror of
https://github.com/golang/go
synced 2024-11-07 10:36:19 -07:00
[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: Cherry Zhang <cherryyz@google.com> Reviewed-by: Jeremy Faller <jeremy@golang.org>
This commit is contained in:
parent
e5acb58c39
commit
6ecaae0325
@ -396,15 +396,6 @@ type Reader struct {
|
|||||||
h Header // keep block offsets
|
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 {
|
func NewReaderFromBytes(b []byte, readonly bool) *Reader {
|
||||||
r := &Reader{b: b, readonly: readonly, rd: bytes.NewReader(b), start: 0}
|
r := &Reader{b: b, readonly: readonly, rd: bytes.NewReader(b), start: 0}
|
||||||
err := r.h.Read(r)
|
err := r.h.Read(r)
|
||||||
@ -418,16 +409,8 @@ func (r *Reader) BytesAt(off uint32, len int) []byte {
|
|||||||
if len == 0 {
|
if len == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if r.b != nil {
|
|
||||||
end := int(off) + len
|
end := int(off) + len
|
||||||
return r.b[int(off):end:end]
|
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Reader) uint64At(off uint32) uint64 {
|
func (r *Reader) uint64At(off uint32) uint64 {
|
||||||
@ -460,19 +443,11 @@ func (r *Reader) uint8At(off uint32) uint8 {
|
|||||||
|
|
||||||
func (r *Reader) StringAt(off uint32) string {
|
func (r *Reader) StringAt(off uint32) string {
|
||||||
l := r.uint32At(off)
|
l := r.uint32At(off)
|
||||||
if r.b != nil {
|
|
||||||
b := r.b[off+4 : off+4+l]
|
b := r.b[off+4 : off+4+l]
|
||||||
if r.readonly {
|
if r.readonly {
|
||||||
return toString(b) // backed by RO memory, ok to make unsafe string
|
return toString(b) // backed by RO memory, ok to make unsafe string
|
||||||
}
|
}
|
||||||
return string(b)
|
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")
|
|
||||||
}
|
|
||||||
return string(b)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func toString(b []byte) string {
|
func toString(b []byte) string {
|
||||||
|
Loading…
Reference in New Issue
Block a user