b2s_old.go 388 B

123456789101112131415
  1. //go:build !go1.20
  2. // +build !go1.20
  3. package fasthttp
  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. //
  8. // Note it may break if string and/or slice header will change
  9. // in the future go versions.
  10. func b2s(b []byte) string {
  11. return *(*string)(unsafe.Pointer(&b))
  12. }