strconv_120.go 449 B

1234567891011121314151617
  1. //go:build go1.20
  2. // +build go1.20
  3. package strconv
  4. import "unsafe"
  5. // B2S converts byte slice to a string without memory allocation.
  6. // See https://groups.google.com/forum/#!msg/Golang-Nuts/ENgbUzYvCuU/90yGx7GUAgAJ .
  7. func B2S(b []byte) string {
  8. return unsafe.String(unsafe.SliceData(b), len(b))
  9. }
  10. // S2B converts string to a byte slice without memory allocation.
  11. func S2B(s string) []byte {
  12. return unsafe.Slice(unsafe.StringData(s), len(s))
  13. }