optimized b2s function (#1483)

This commit is contained in:
orangesobeautiful
2023-02-08 15:24:24 +08:00
committed by GitHub
parent 2e81dca7b2
commit b0fe6f00d2
+1 -5
View File
@@ -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))
}