b2s_old.go 370 B

1234567891011121314
  1. //go:build !go1.20
  2. package fasthttp
  3. import "unsafe"
  4. // b2s converts byte slice to a string without memory allocation.
  5. // See https://groups.google.com/forum/#!msg/Golang-Nuts/ENgbUzYvCuU/90yGx7GUAgAJ .
  6. //
  7. // Note it may break if string and/or slice header will change
  8. // in the future go versions.
  9. func b2s(b []byte) string {
  10. return *(*string)(unsafe.Pointer(&b))
  11. }