Skip to content

Commit

Permalink
Use unsafe.string instead of unsafe.pointer
Browse files Browse the repository at this point in the history
This only a cosmetic change, the speed seems to be exactly the same
  • Loading branch information
karelbilek committed Oct 10, 2024
1 parent 9279415 commit b0daf5d
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion msgp/unsafe.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ const (
// THIS IS EVIL CODE.
// YOU HAVE BEEN WARNED.
func UnsafeString(b []byte) string {
return *(*string)(unsafe.Pointer(&b))
var p *byte
l := len(b)
if l != 0 {
p = &b[0]
}
return unsafe.String(p, l)
}

// UnsafeBytes returns the string as a byte slice
Expand Down

0 comments on commit b0daf5d

Please sign in to comment.