]> Cypherpunks repositories - gostls13.git/commitdiff
os: use unsafe.{Slice,StringData} instead of unsafeheader package
authorTobias Klauser <tklauser@distanz.ch>
Wed, 7 Sep 2022 12:07:12 +0000 (14:07 +0200)
committerGopher Robot <gobot@golang.org>
Thu, 8 Sep 2022 21:18:58 +0000 (21:18 +0000)
Change-Id: I213b078effa4b7049c44498d651de5b938e5404b
Reviewed-on: https://go-review.googlesource.com/c/go/+/428779
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: hopehook <hopehook@golangcn.org>
Run-TryBot: hopehook <hopehook@golangcn.org>
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>

src/os/file.go

index 9f388921aed99ad31bcbf58bc2e830f0047a61a9..e2eef8ec5d30dc3427a047dab66c87e6ff642cd6 100644 (file)
@@ -43,7 +43,6 @@ import (
        "errors"
        "internal/poll"
        "internal/testlog"
-       "internal/unsafeheader"
        "io"
        "io/fs"
        "runtime"
@@ -247,11 +246,7 @@ func (f *File) Seek(offset int64, whence int) (ret int64, err error) {
 // WriteString is like Write, but writes the contents of string s rather than
 // a slice of bytes.
 func (f *File) WriteString(s string) (n int, err error) {
-       var b []byte
-       hdr := (*unsafeheader.Slice)(unsafe.Pointer(&b))
-       hdr.Data = (*unsafeheader.String)(unsafe.Pointer(&s)).Data
-       hdr.Cap = len(s)
-       hdr.Len = len(s)
+       b := unsafe.Slice(unsafe.StringData(s), len(s))
        return f.Write(b)
 }