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>
"errors"
"internal/poll"
"internal/testlog"
- "internal/unsafeheader"
"io"
"io/fs"
"runtime"
// 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)
}