]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.link] cmd/link: remove unused slow paths from BytesAt/StringAt
authorThan McIntosh <thanm@google.com>
Wed, 16 Oct 2019 14:39:58 +0000 (10:39 -0400)
committerThan McIntosh <thanm@google.com>
Thu, 17 Oct 2019 14:20:15 +0000 (14:20 +0000)
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>
src/cmd/internal/goobj2/objfile.go

index 03b322da6c7c0de1e5ff76391f38ce8548a9f29b..e10ce43833efca233a87b533fc5fbbec966cc95e 100644 (file)
@@ -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)
 }