cmd/internal/gc: remove namebuf variable
namebuf was a global char buffer in the C version of gc, which was
useful for providing common storage for constructing symbol and file
names. However, now that it's just a global Go string and the string
data is dynamically allocated anyway, it doesn't serve any purpose
except to force extra write barriers everytime it's assigned to.
Also, introduce Lookupf(fmt, args...) as shorthand for
Lookup(fmt.Sprintf(fmt, args...)), which was a very common pattern for
using namebuf.
Passes "go build -toolexec 'toolstash -cmp' -a std".
Notably, this CL shrinks 6g's text section by ~15kB:
$ size toolstash/6g tool/linux_amd64/6g
text data bss dec hex filename
4600805 605968 342988 5549761 54aec1 toolstash/6g
4585547 605968 342956 5534471 547307 tool/linux_amd64/6g
Change-Id: I98abb44fc7f43a2e2e48425cc9f215cd0be37442
Reviewed-on: https://go-review.googlesource.com/7080
Reviewed-by: Ian Lance Taylor <iant@golang.org>
diff --git a/src/cmd/internal/gc/walk.go b/src/cmd/internal/gc/walk.go
index e88b4c2..e4abc28 100644
--- a/src/cmd/internal/gc/walk.go
+++ b/src/cmd/internal/gc/walk.go
@@ -1109,17 +1109,18 @@
if Widthreg >= 8 || (et != TUINT64 && et != TINT64) {
goto ret
}
+ var fn string
if et == TINT64 {
- namebuf = "int64"
+ fn = "int64"
} else {
- namebuf = "uint64"
+ fn = "uint64"
}
if n.Op == ODIV {
- namebuf += "div"
+ fn += "div"
} else {
- namebuf += "mod"
+ fn += "mod"
}
- n = mkcall(namebuf, n.Type, init, conv(n.Left, Types[et]), conv(n.Right, Types[et]))
+ n = mkcall(fn, n.Type, init, conv(n.Left, Types[et]), conv(n.Right, Types[et]))
default:
break
@@ -2882,13 +2883,14 @@
args = list(args, conv(l.N, Types[TSTRING]))
}
+ var fn string
if c <= 5 {
// small numbers of strings use direct runtime helpers.
// note: orderexpr knows this cutoff too.
- namebuf = fmt.Sprintf("concatstring%d", c)
+ fn = fmt.Sprintf("concatstring%d", c)
} else {
// large numbers of strings are passed to the runtime as a slice.
- namebuf = "concatstrings"
+ fn = "concatstrings"
t := typ(TARRAY)
t.Type = Types[TSTRING]
@@ -2901,7 +2903,7 @@
slice.Esc = EscNone
}
- cat := syslook(namebuf, 1)
+ cat := syslook(fn, 1)
r := Nod(OCALL, cat, nil)
r.List = args
typecheck(&r, Erv)