bytestostr.go raw

   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  
   5  //+build !easyjson_nounsafe
   6  //+build !appengine
   7  
   8  package jlexer
   9  
  10  import (
  11  	"unsafe"
  12  )
  13  
  14  // bytesToStr creates a string pointing at the slice to avoid copying.
  15  //
  16  // Warning: the string returned by the function should be used with care, as the whole input data
  17  // chunk may be either blocked from being freed by GC because of a single string or the buffer.Data
  18  // may be garbage-collected even when the string exists.
  19  func bytesToStr(data []byte) string {
  20  	return *(*string)(unsafe.Pointer(&data))
  21  }
  22