]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/internal/ld: remove pointless allocs
authorJosh Bleecher Snyder <josharian@gmail.com>
Sat, 25 Apr 2015 03:24:49 +0000 (20:24 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Mon, 27 Apr 2015 17:08:56 +0000 (17:08 +0000)
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/9391
Reviewed-by: David Crawshaw <crawshaw@golang.org>
src/cmd/internal/ld/dwarf.go
src/cmd/internal/ld/go.go
src/cmd/internal/ld/objfile.go

index ec540fdd77e5a490818866f7ff8981d26a374e32..6d90404b13e07049435d03e6fd36365dd4c896fd 100644 (file)
@@ -158,16 +158,16 @@ func sleb128enc(v int64, dst []byte) int {
        return int(length)
 }
 
+var encbuf [10]byte
+
 func uleb128put(v int64) {
-       var buf [10]byte
-       n := uleb128enc(uint64(v), buf[:])
-       Cwrite(buf[:n])
+       n := uleb128enc(uint64(v), encbuf[:])
+       Cwrite(encbuf[:n])
 }
 
 func sleb128put(v int64) {
-       var buf [10]byte
-       n := sleb128enc(v, buf[:])
-       Cwrite(buf[:n])
+       n := sleb128enc(v, encbuf[:])
+       Cwrite(encbuf[:n])
 }
 
 /*
index e6756ab387cb033e647cc7bf24f8f362653ec10f..06f1d87e6a52ab63a47a71cbef9f8dd197231ec6 100644 (file)
@@ -2,6 +2,8 @@
 // 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).
+
 package ld
 
 import (
@@ -20,12 +22,6 @@ func expandpkg(t0 string, pkg string) string {
        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.
 // check for inconsistencies.
 
index 41534c857c54eccd2d1d2b22524c2df01316621f..8eac63497e5d1a97360769d07c726a80d8972d79 100644 (file)
@@ -80,8 +80,7 @@ func readsym(ctxt *Link, f *Biobuf, pkg string, pn string) {
        }
        size := int(rdint(f))
        typ := rdsym(ctxt, f, pkg)
-       var data []byte
-       rddata(f, &data)
+       data := rddata(f)
        nreloc := int(rdint(f))
 
        if v != 0 {
@@ -183,14 +182,14 @@ overwrite:
 
                s.Pcln = new(Pcln)
                pc := s.Pcln
-               rddata(f, &pc.Pcsp.P)
-               rddata(f, &pc.Pcfile.P)
-               rddata(f, &pc.Pcline.P)
+               pc.Pcsp.P = rddata(f)
+               pc.Pcfile.P = rddata(f)
+               pc.Pcline.P = rddata(f)
                n = int(rdint(f))
                pc.Pcdata = make([]Pcdata, n)
                pc.Npcdata = n
                for i := 0; i < n; i++ {
-                       rddata(f, &pc.Pcdata[i].P)
+                       pc.Pcdata[i].P = rddata(f)
                }
                n = int(rdint(f))
                pc.Funcdata = make([]*LSym, n)
@@ -302,10 +301,11 @@ func rdstring(f *Biobuf) string {
        return string(p)
 }
 
-func rddata(f *Biobuf, pp *[]byte) {
+func rddata(f *Biobuf) []byte {
        n := rdint(f)
-       *pp = make([]byte, n)
-       Bread(f, *pp)
+       p := make([]byte, n)
+       Bread(f, p)
+       return p
 }
 
 var symbuf []byte