1
0
mirror of https://github.com/golang/go synced 2024-11-23 15:00:03 -07:00

cmd/compile: simplify slicebytes

Use slicesym to implement. Remove len param.

Passes toolstash-check.

Change-Id: Ia6d4fb2a3b476eceeba60979b4dd82b634b43939
Reviewed-on: https://go-review.googlesource.com/c/go/+/228887
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
Josh Bleecher Snyder 2020-04-10 21:33:27 -07:00
parent ea52c78a66
commit ed5233166f
2 changed files with 5 additions and 8 deletions

View File

@ -365,11 +365,12 @@ func stringsym(pos src.XPos, s string) (data *obj.LSym) {
var slicebytes_gen int
func slicebytes(nam *Node, s string, len int) {
func slicebytes(nam *Node, s string) {
slicebytes_gen++
symname := fmt.Sprintf(".gobytes.%d", slicebytes_gen)
sym := localpkg.Lookup(symname)
sym.Def = asTypesNode(newname(sym))
symnode := newname(sym)
sym.Def = asTypesNode(symnode)
lsym := sym.Linksym()
off := dsname(lsym, 0, s, nam.Pos, "slice")
@ -378,11 +379,7 @@ func slicebytes(nam *Node, s string, len int) {
if nam.Op != ONAME {
Fatalf("slicebytes %v", nam)
}
nsym := nam.Sym.Linksym()
off = int(nam.Xoffset)
off = dsymptr(nsym, off, lsym, 0)
off = duintptr(nsym, off, uint64(len))
duintptr(nsym, off, uint64(len))
slicesym(nam, symnode, int64(len(s)))
}
func dsname(s *obj.LSym, off int, t string, pos src.XPos, what string) int {

View File

@ -208,7 +208,7 @@ func (s *InitSchedule) staticassign(l *Node, r *Node) bool {
case OSTR2BYTES:
if l.Class() == PEXTERN && r.Left.Op == OLITERAL {
sval := strlit(r.Left)
slicebytes(l, sval, len(sval))
slicebytes(l, sval)
return true
}