From 1688a76ac48bb127d57223ae0c3066d2d5d3699f 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 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/msgp/unsafe.go b/msgp/unsafe.go index 7d36bfb1..c16c224f 100644 --- a/msgp/unsafe.go +++ b/msgp/unsafe.go @@ -24,7 +24,11 @@ const ( // THIS IS EVIL CODE. // YOU HAVE BEEN WARNED. func UnsafeString(b []byte) string { - return *(*string)(unsafe.Pointer(&b)) + l := len(b) + if l == 0 { + return "" + } + return unsafe.String(&b[0], l) } // UnsafeBytes returns the string as a byte slice