convert_s2b_new.go 203 B

123456789101112
  1. //go:build go1.20
  2. package utils
  3. import (
  4. "unsafe"
  5. )
  6. // UnsafeBytes returns a byte pointer without allocation.
  7. func UnsafeBytes(s string) []byte {
  8. return unsafe.Slice(unsafe.StringData(s), len(s))
  9. }