http urls monitor.

bytestostr.go 768B

12345678910111213141516171819202122232425
  1. // This file will only be included to the build if neither
  2. // easyjson_nounsafe nor appengine build tag is set. See README notes
  3. // for more details.
  4. //+build !easyjson_nounsafe
  5. //+build !appengine
  6. package jlexer
  7. import (
  8. "reflect"
  9. "unsafe"
  10. )
  11. // bytesToStr creates a string pointing at the slice to avoid copying.
  12. //
  13. // Warning: the string returned by the function should be used with care, as the whole input data
  14. // chunk may be either blocked from being freed by GC because of a single string or the buffer.Data
  15. // may be garbage-collected even when the string exists.
  16. func bytesToStr(data []byte) string {
  17. h := (*reflect.SliceHeader)(unsafe.Pointer(&data))
  18. shdr := reflect.StringHeader{Data: h.Data, Len: h.Len}
  19. return *(*string)(unsafe.Pointer(&shdr))
  20. }