mirror of
https://github.com/golang/go.git
synced 2024-09-21 18:38:37 +00:00
runtime: simplify code using unsafe.{Slice,String}
Updates #54854 Change-Id: Ie18665e93e477b6f220acf4c6c070b2af4343064 Reviewed-on: https://go-review.googlesource.com/c/go/+/428157 Run-TryBot: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Bryan Mills <bcmills@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
This commit is contained in:
parent
2ee075dc47
commit
4fe4601d37
@ -657,11 +657,7 @@ func (r *debugLogReader) printVal() bool {
|
||||
case debugLogConstString:
|
||||
len, ptr := int(r.uvarint()), uintptr(r.uvarint())
|
||||
ptr += firstmoduledata.etext
|
||||
str := stringStruct{
|
||||
str: unsafe.Pointer(ptr),
|
||||
len: len,
|
||||
}
|
||||
s := *(*string)(unsafe.Pointer(&str))
|
||||
s := unsafe.String((*byte)(unsafe.Pointer(ptr)), len)
|
||||
print(s)
|
||||
|
||||
case debugLogStringOverflow:
|
||||
|
@ -6,7 +6,6 @@ package runtime_test
|
||||
|
||||
import (
|
||||
"os"
|
||||
"reflect"
|
||||
"syscall"
|
||||
"testing"
|
||||
"unsafe"
|
||||
@ -45,11 +44,7 @@ func TestMemmoveOverflow(t *testing.T) {
|
||||
defer syscall.Syscall(syscall.SYS_MUNMAP, base+off, 65536, 0)
|
||||
}
|
||||
|
||||
var s []byte
|
||||
sp := (*reflect.SliceHeader)(unsafe.Pointer(&s))
|
||||
sp.Data = base
|
||||
sp.Len, sp.Cap = 3<<30, 3<<30
|
||||
|
||||
s := unsafe.Slice((*byte)(unsafe.Pointer(base)), 3<<30)
|
||||
n := copy(s[1:], s)
|
||||
if n != 3<<30-1 {
|
||||
t.Fatalf("copied %d bytes, expected %d", n, 3<<30-1)
|
||||
|
@ -620,7 +620,7 @@ func cpuinit() {
|
||||
|
||||
for i := int32(0); i < n; i++ {
|
||||
p := argv_index(argv, argc+1+i)
|
||||
s := *(*string)(unsafe.Pointer(&stringStruct{unsafe.Pointer(p), findnull(p)}))
|
||||
s := unsafe.String(p, findnull(p))
|
||||
|
||||
if hasPrefix(s, prefix) {
|
||||
env = gostring(p)[len(prefix):]
|
||||
|
Loading…
Reference in New Issue
Block a user