]> Cypherpunks repositories - gostls13.git/commitdiff
syscall: simplify code using unsafe.Slice
authorcuiweixie <cuiweixie@gmail.com>
Sat, 3 Sep 2022 10:18:30 +0000 (18:18 +0800)
committerGopher Robot <gobot@golang.org>
Wed, 7 Sep 2022 01:48:31 +0000 (01:48 +0000)
Updates #54854

Change-Id: Ibaf4eea14a6259cdbca79e9e95db1602966f18e6
Reviewed-on: https://go-review.googlesource.com/c/go/+/428176
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/syscall/syscall_darwin.go

index 663bd98c104f517dba0a351b268dcdcac4907299..663ac4e94c3b07bf63e3b6089f71667fa9633fc6 100644 (file)
@@ -310,12 +310,7 @@ func Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) {
                        break
                }
                // Copy entry into return buffer.
-               s := struct {
-                       ptr unsafe.Pointer
-                       siz int
-                       cap int
-               }{ptr: unsafe.Pointer(&entry), siz: reclen, cap: reclen}
-               copy(buf, *(*[]byte)(unsafe.Pointer(&s)))
+               copy(buf, unsafe.Slice((*byte)(unsafe.Pointer(&entry)), reclen))
                buf = buf[reclen:]
                n += reclen
                cnt++