From ea3885c6df29651d96966afededbce1af4210abc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=A2=E8=87=B4=E9=82=A6=20=28XIE=20Zhibang=29?= Date: Thu, 19 May 2022 13:34:53 +0000 Subject: [PATCH] mountinfo_openbsd: Rewrite int8SliceToString with unsafe MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 谢致邦 (XIE Zhibang) --- mountinfo/mountinfo_openbsd.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/mountinfo/mountinfo_openbsd.go b/mountinfo/mountinfo_openbsd.go index 78ea8cf3..e2037c48 100644 --- a/mountinfo/mountinfo_openbsd.go +++ b/mountinfo/mountinfo_openbsd.go @@ -1,16 +1,19 @@ package mountinfo -import "golang.org/x/sys/unix" +import ( + "unsafe" + + "golang.org/x/sys/unix" +) func int8SliceToString(is []int8) string { - var bs []byte - for _, i := range is { - if i == 0 { + for i := range is { + if is[i] == 0 { + is = is[:i] break } - bs = append(bs, byte(i)) } - return string(bs) + return *(*string)(unsafe.Pointer(&is)) } func getMountinfo(entry *unix.Statfs_t) *Info {