Skip to content

Commit

Permalink
Add reference implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
ostafen committed Apr 15, 2024
1 parent 03213dc commit a4e7599
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions pkg/helpers/slices/slices.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
// BytesToString converts bytes to a string without memory allocation.
// NOTE: The given bytes MUST NOT be modified since they share the same backing array
// with the returned string.
// Reference implementation: https://github.com/golang/go/blob/ad7c32dc3b6d5edc3dd72b3e15c80dc4f4c27064/src/strings/builder.go#L47.
func BytesToString(bs []byte) string {
return *(*string)(unsafe.Pointer(&bs))
}

0 comments on commit a4e7599

Please sign in to comment.