1
0
mirror of https://github.com/golang/go synced 2024-11-19 06:54:39 -07:00

cmd/internal/gc, runtime: change growslice to use int instead of int64

Gc already calculates n as an int, so converting to int64 to call
growslice doesn't serve any purpose except to emit slightly larger
code on 32-bit platforms.  Passing n as an int shrinks godoc's text
segment by 8kB (9472633 => 9464133) when building for ARM.

Change-Id: Ief9492c21d01afcb624d3f2a484df741450b788d
Reviewed-on: https://go-review.googlesource.com/6231
Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Matthew Dempsky 2015-02-27 15:13:05 +09:00 committed by Dmitry Vyukov
parent 3d0397a4f4
commit 81d4072eb0
4 changed files with 9 additions and 12 deletions

View File

@ -128,7 +128,7 @@ const runtimeimport = "" +
"func @\"\".selectgo (@\"\".sel·1 *byte)\n" +
"func @\"\".block ()\n" +
"func @\"\".makeslice (@\"\".typ·2 *byte, @\"\".nel·3 int64, @\"\".cap·4 int64) (@\"\".ary·1 []any)\n" +
"func @\"\".growslice (@\"\".typ·2 *byte, @\"\".old·3 []any, @\"\".n·4 int64) (@\"\".ary·1 []any)\n" +
"func @\"\".growslice (@\"\".typ·2 *byte, @\"\".old·3 []any, @\"\".n·4 int) (@\"\".ary·1 []any)\n" +
"func @\"\".memmove (@\"\".to·1 *any, @\"\".frm·2 *any, @\"\".length·3 uintptr)\n" +
"func @\"\".memclr (@\"\".ptr·1 *byte, @\"\".length·2 uintptr)\n" +
"func @\"\".memequal (@\"\".x·2 *any, @\"\".y·3 *any, @\"\".size·4 uintptr) (? bool)\n" +

View File

@ -159,7 +159,7 @@ func selectgo(sel *byte)
func block()
func makeslice(typ *byte, nel int64, cap int64) (ary []any)
func growslice(typ *byte, old []any, n int64) (ary []any)
func growslice(typ *byte, old []any, n int) (ary []any)
func memmove(to *any, frm *any, length uintptr)
func memclr(ptr *byte, length uintptr)

View File

@ -2949,14 +2949,14 @@ func appendslice(n *Node, init **NodeList) *Node {
nif.Ntest = Nod(OGT, nt, Nodintconst(0))
// instantiate growslice(Type*, []any, int64) []any
// instantiate growslice(Type*, []any, int) []any
fn := syslook("growslice", 1)
argtype(fn, s.Type.Type)
argtype(fn, s.Type.Type)
// s = growslice(T, s, n)
nif.Nbody = list1(Nod(OAS, s, mkcall1(fn, s.Type, &nif.Ninit, typename(s.Type), s, conv(nt, Types[TINT64]))))
nif.Nbody = list1(Nod(OAS, s, mkcall1(fn, s.Type, &nif.Ninit, typename(s.Type), s, nt)))
l = list(l, nif)
@ -3066,11 +3066,11 @@ func walkappend(n *Node, init **NodeList) *Node {
nx := Nod(OIF, nil, nil) // if cap(s) - len(s) < argc
nx.Ntest = Nod(OLT, Nod(OSUB, Nod(OCAP, ns, nil), Nod(OLEN, ns, nil)), na)
fn := syslook("growslice", 1) // growslice(<type>, old []T, n int64) (ret []T)
fn := syslook("growslice", 1) // growslice(<type>, old []T, n int) (ret []T)
argtype(fn, ns.Type.Type) // 1 old []any
argtype(fn, ns.Type.Type) // 2 ret []any
nx.Nbody = list1(Nod(OAS, ns, mkcall1(fn, ns.Type, &nx.Ninit, typename(ns.Type), ns, conv(na, Types[TINT64]))))
nx.Nbody = list1(Nod(OAS, ns, mkcall1(fn, ns.Type, &nx.Ninit, typename(ns.Type), ns, na)))
l = list(l, nx)

View File

@ -33,16 +33,13 @@ func makeslice(t *slicetype, len64 int64, cap64 int64) sliceStruct {
return sliceStruct{p, len, cap}
}
// TODO: take uintptr instead of int64?
func growslice(t *slicetype, old sliceStruct, n int64) sliceStruct {
func growslice(t *slicetype, old sliceStruct, n int) sliceStruct {
if n < 1 {
panic(errorString("growslice: invalid n"))
}
cap64 := int64(old.cap) + n
cap := int(cap64)
if int64(cap) != cap64 || cap < old.cap || t.elem.size > 0 && uintptr(cap) > _MaxMem/uintptr(t.elem.size) {
cap := old.cap + n
if cap < old.cap || t.elem.size > 0 && uintptr(cap) > _MaxMem/uintptr(t.elem.size) {
panic(errorString("growslice: cap out of range"))
}