Skip to content

Commit

Permalink
optimized b2s function (#1483)
Browse files Browse the repository at this point in the history
  • Loading branch information
orangesobeautiful committed Feb 8, 2023
1 parent 2e81dca commit b0fe6f0
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions b2s_new.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

0 comments on commit b0fe6f0

Please sign in to comment.