Skip to content

Commit

Permalink
feat: fast encodeUUID
Browse files Browse the repository at this point in the history
  • Loading branch information
slipros authored and jackc committed Jan 21, 2024
1 parent a4ca091 commit 517c654
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion pgtype/uuid.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,19 @@ func parseUUID(src string) (dst [16]byte, err error) {

// encodeUUID converts a uuid byte array to UUID standard string form.
func encodeUUID(src [16]byte) string {
return fmt.Sprintf("%x-%x-%x-%x-%x", src[0:4], src[4:6], src[6:8], src[8:10], src[10:16])
var buf [36]byte

hex.Encode(buf[0:8], src[:4])
buf[8] = '-'
hex.Encode(buf[9:13], src[4:6])
buf[13] = '-'
hex.Encode(buf[14:18], src[6:8])
buf[18] = '-'
hex.Encode(buf[19:23], src[8:10])
buf[23] = '-'
hex.Encode(buf[24:], src[10:])

return string(buf[:])
}

// Scan implements the database/sql Scanner interface.
Expand Down

0 comments on commit 517c654

Please sign in to comment.