Commit 2692f483 authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

cmd/internal/ld: remove pointless allocs

Reduces allocs linking cmd/go and runtime.test
by ~13%. No functional changes.

The most easily addressed sources of allocations
after this are expandpkg, rdstring, and symbuf
string conversion.

These can be reduced by interning strings,
but that increases the overall memory footprint.

Change-Id: Ifedefc9f2a0403bcc75460d6b139e8408374e058
Reviewed-on: https://go-review.googlesource.com/9391Reviewed-by: default avatarDavid Crawshaw <crawshaw@golang.org>
parent 4a3e000a
...@@ -158,16 +158,16 @@ func sleb128enc(v int64, dst []byte) int { ...@@ -158,16 +158,16 @@ func sleb128enc(v int64, dst []byte) int {
return int(length) return int(length)
} }
var encbuf [10]byte
func uleb128put(v int64) { func uleb128put(v int64) {
var buf [10]byte n := uleb128enc(uint64(v), encbuf[:])
n := uleb128enc(uint64(v), buf[:]) Cwrite(encbuf[:n])
Cwrite(buf[:n])
} }
func sleb128put(v int64) { func sleb128put(v int64) {
var buf [10]byte n := sleb128enc(v, encbuf[:])
n := sleb128enc(v, buf[:]) Cwrite(encbuf[:n])
Cwrite(buf[:n])
} }
/* /*
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
// go-specific code shared across loaders (5l, 6l, 8l).
package ld package ld
import ( import (
...@@ -20,12 +22,6 @@ func expandpkg(t0 string, pkg string) string { ...@@ -20,12 +22,6 @@ func expandpkg(t0 string, pkg string) string {
return strings.Replace(t0, `"".`, pkg+".", -1) return strings.Replace(t0, `"".`, pkg+".", -1)
} }
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// go-specific code shared across loaders (5l, 6l, 8l).
// accumulate all type information from .6 files. // accumulate all type information from .6 files.
// check for inconsistencies. // check for inconsistencies.
......
...@@ -80,8 +80,7 @@ func readsym(ctxt *Link, f *Biobuf, pkg string, pn string) { ...@@ -80,8 +80,7 @@ func readsym(ctxt *Link, f *Biobuf, pkg string, pn string) {
} }
size := int(rdint(f)) size := int(rdint(f))
typ := rdsym(ctxt, f, pkg) typ := rdsym(ctxt, f, pkg)
var data []byte data := rddata(f)
rddata(f, &data)
nreloc := int(rdint(f)) nreloc := int(rdint(f))
if v != 0 { if v != 0 {
...@@ -183,14 +182,14 @@ overwrite: ...@@ -183,14 +182,14 @@ overwrite:
s.Pcln = new(Pcln) s.Pcln = new(Pcln)
pc := s.Pcln pc := s.Pcln
rddata(f, &pc.Pcsp.P) pc.Pcsp.P = rddata(f)
rddata(f, &pc.Pcfile.P) pc.Pcfile.P = rddata(f)
rddata(f, &pc.Pcline.P) pc.Pcline.P = rddata(f)
n = int(rdint(f)) n = int(rdint(f))
pc.Pcdata = make([]Pcdata, n) pc.Pcdata = make([]Pcdata, n)
pc.Npcdata = n pc.Npcdata = n
for i := 0; i < n; i++ { for i := 0; i < n; i++ {
rddata(f, &pc.Pcdata[i].P) pc.Pcdata[i].P = rddata(f)
} }
n = int(rdint(f)) n = int(rdint(f))
pc.Funcdata = make([]*LSym, n) pc.Funcdata = make([]*LSym, n)
...@@ -302,10 +301,11 @@ func rdstring(f *Biobuf) string { ...@@ -302,10 +301,11 @@ func rdstring(f *Biobuf) string {
return string(p) return string(p)
} }
func rddata(f *Biobuf, pp *[]byte) { func rddata(f *Biobuf) []byte {
n := rdint(f) n := rdint(f)
*pp = make([]byte, n) p := make([]byte, n)
Bread(f, *pp) Bread(f, p)
return p
} }
var symbuf []byte var symbuf []byte
......
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