From b0daf5da3085c2dcfd59b3dc8eb7a29a3e801f59 Mon Sep 17 00:00:00 2001 From: Karel Bilek Date: Thu, 10 Oct 2024 12:02:39 +0200 Subject: [PATCH] Use unsafe.string instead of unsafe.pointer This only a cosmetic change, the speed seems to be exactly the same --- msgp/unsafe.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/msgp/unsafe.go b/msgp/unsafe.go index 7d36bfb1..15a95505 100644 --- a/msgp/unsafe.go +++ b/msgp/unsafe.go @@ -24,7 +24,12 @@ const ( // THIS IS EVIL CODE. // YOU HAVE BEEN WARNED. func UnsafeString(b []byte) string { - return *(*string)(unsafe.Pointer(&b)) + var p *byte + l := len(b) + if l != 0 { + p = &b[0] + } + return unsafe.String(p, l) } // UnsafeBytes returns the string as a byte slice