Hello rsc@golang.org, lvd@gmail.com, golang-dev@googlegroups.com (cc: golang-dev@googlegroups.com), I'd like you to review this change to https://go.googlecode.com/hg/
12 years, 6 months ago
(2013-01-12 07:42:03 UTC)
#1
- It could be enabled by default if useful - I have a test for ...
12 years, 6 months ago
(2013-01-12 07:43:09 UTC)
#2
- It could be enabled by default if useful
- I have a test for this but not sure where to put it:
package main
func sum(a ...int) int {
if len(a) == 0 {
return 0
}
s := a[0] + a[1] + a[2]
return s
}
func sum2(a int, b ...int) int {
s := a + b[0] + b[1]
return s
}
func N() (a, b, c int) { return 1, 2, 3 }
func main() {
u, v, w := 1, 2, 3
s := sum(u, v, w)
if s != 6 {
panic(s)
}
s = sum2(u, v, w)
if s != 6 {
panic(s)
}
s = sum(N())
if s != 6 {
panic(s)
}
s = sum2(N())
if s != 6 {
panic(s)
}
V := []int{1, 2, 3}
s = sum(V...)
if s != 6 {
panic(s)
}
s = sum2(3, V...)
if s != 6 {
panic(s)
}
s = sum()
if s != 0 {
panic(s)
}
}
The following functions in the std library are simple enough to be inlined with this ...
12 years, 6 months ago
(2013-01-12 07:46:31 UTC)
#3
The following functions in the std library are simple enough to be inlined with
this patch:
src/pkg/io/multi.go:30: should inline MultiReader but it's variadic
src/pkg/io/multi.go:54: should inline MultiWriter but it's variadic
src/pkg/text/template/parse/parse.go:112: should inline New but it's variadic
src/cmd/cgo/gcc.go:1021: should inline (*TypeRepr).Set but it's variadic
src/cmd/cgo/out.go:895: should inline c but it's variadic
src/pkg/html/template/html.go:255: should inline commentEscaper but it's
variadic
On 2013/1/13 Daniel Theophanes <kardianos@gmail.com> wrote: > Would it be correct to say, this in-lines ...
12 years, 6 months ago
(2013-01-13 09:52:41 UTC)
#6
On 2013/1/13 Daniel Theophanes <kardianos@gmail.com> wrote:
> Would it be correct to say, this in-lines the functions but doesn't save an
> alloc for the slice?
>
> Thanks,
> -Daniel
It works like a normal call. Thanks to escape analysis even in normal
variadic calls, it can happen that the slice data is on the stack.
Rémy.
https://codereview.appspot.com/7093050/diff/19002/src/cmd/gc/inl.c File src/cmd/gc/inl.c (right): https://codereview.appspot.com/7093050/diff/19002/src/cmd/gc/inl.c#newcode621 src/cmd/gc/inl.c:621: if(n->list->n->left->type->outtuple > 1) had to correct a little typo ...
12 years, 5 months ago
(2013-01-31 07:41:35 UTC)
#13
Issue 7093050: code review 7093050: cmd/gc: inlining of variadic functions.
(Closed)
Created 12 years, 6 months ago by remyoudompheng
Modified 12 years, 5 months ago
Reviewers:
Base URL:
Comments: 2