本站源代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
768B

  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. }
上海开阖软件有限公司 沪ICP备12045867号-1