zerocopy.go 304 B

1234567891011121314151617181920
  1. // +build !appengine
  2. package plist
  3. import (
  4. "reflect"
  5. "unsafe"
  6. )
  7. func zeroCopy8BitString(buf []byte, off int, len int) string {
  8. if len == 0 {
  9. return ""
  10. }
  11. var s string
  12. hdr := (*reflect.StringHeader)(unsafe.Pointer(&s))
  13. hdr.Data = uintptr(unsafe.Pointer(&buf[off]))
  14. hdr.Len = len
  15. return s
  16. }