From 517c654e2cfa7f953bf3e7ac44fe2260cfde669a Mon Sep 17 00:00:00 2001 From: Kirill Malikov Date: Sat, 20 Jan 2024 13:49:26 +0300 Subject: [PATCH] feat: fast encodeUUID --- pgtype/uuid.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/pgtype/uuid.go b/pgtype/uuid.go index b59d6e766..d57c0f2fa 100644 --- a/pgtype/uuid.go +++ b/pgtype/uuid.go @@ -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.