Skip to content

Commit

Permalink
Perform conversion from string to []byte according to rule wundergraph#6
Browse files Browse the repository at this point in the history
  • Loading branch information
valyala committed Aug 5, 2020
1 parent 44caf1e commit ecab8fa
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ func b2s(b []byte) string {
return *(*string)(unsafe.Pointer(&b))
}

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

const maxStartEndStringLen = 80
Expand Down

0 comments on commit ecab8fa

Please sign in to comment.