gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

faststr.go (761B)


      1 package base64x
      2 
      3 import (
      4     `reflect`
      5     `unsafe`
      6 )
      7 
      8 func mem2str(v []byte) (s string) {
      9     (*reflect.StringHeader)(unsafe.Pointer(&s)).Len  = (*reflect.SliceHeader)(unsafe.Pointer(&v)).Len
     10     (*reflect.StringHeader)(unsafe.Pointer(&s)).Data = (*reflect.SliceHeader)(unsafe.Pointer(&v)).Data
     11     return
     12 }
     13 
     14 func str2mem(s string) (v []byte) {
     15     (*reflect.SliceHeader)(unsafe.Pointer(&v)).Cap  = (*reflect.StringHeader)(unsafe.Pointer(&s)).Len
     16     (*reflect.SliceHeader)(unsafe.Pointer(&v)).Len  = (*reflect.StringHeader)(unsafe.Pointer(&s)).Len
     17     (*reflect.SliceHeader)(unsafe.Pointer(&v)).Data = (*reflect.StringHeader)(unsafe.Pointer(&s)).Data
     18     return
     19 }
     20 
     21 func mem2addr(v []byte) unsafe.Pointer {
     22     return *(*unsafe.Pointer)(unsafe.Pointer(&v))
     23 }