Apr 19, 2017

[Go] best way to copy string

func Copy(s string) string { 
        var b []byte 
        h := (*reflect.SliceHeader)(unsafe.Pointer(&b)) 
        h.Data = (*reflect.StringHeader)(unsafe.Pointer(&s)).Data 
        h.Len = len(s) 
        h.Cap = len(s) 
        return string(b) 
} 

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.