From b0fe6f00d20b7a7e16589757d660be45520097b3 Mon Sep 17 00:00:00 2001 From: orangesobeautiful <74104118+orangesobeautiful@users.noreply.github.com> Date: Wed, 8 Feb 2023 15:24:24 +0800 Subject: [PATCH] optimized b2s function (#1483) --- b2s_new.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/b2s_new.go b/b2s_new.go index 2cbf5e3391..2f7d6f7e62 100644 --- a/b2s_new.go +++ b/b2s_new.go @@ -8,9 +8,5 @@ import "unsafe" // b2s converts byte slice to a string without memory allocation. // See https://groups.google.com/forum/#!msg/Golang-Nuts/ENgbUzYvCuU/90yGx7GUAgAJ . func b2s(b []byte) string { - if len(b) == 0 { - return "" - } - - return unsafe.String(&b[0], len(b)) + return unsafe.String(unsafe.SliceData(b), len(b)) }