From a435eb56f223f81c6d95c329c811ff54cb715594 Mon Sep 17 00:00:00 2001 From: Qiu shao Date: Sat, 24 May 2025 16:41:21 +0800 Subject: [PATCH] perf(hash): optimize Md5Hex encoding performance (#4891) --- core/hash/hash.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core/hash/hash.go b/core/hash/hash.go index 8bd87b596..9a6169930 100644 --- a/core/hash/hash.go +++ b/core/hash/hash.go @@ -2,7 +2,7 @@ package hash import ( "crypto/md5" - "fmt" + "encoding/hex" "github.com/spaolacci/murmur3" ) @@ -20,6 +20,7 @@ func Md5(data []byte) []byte { } // Md5Hex returns the md5 hex string of data. +// This function is optimized for better performance than fmt.Sprintf. func Md5Hex(data []byte) string { - return fmt.Sprintf("%x", Md5(data)) + return hex.EncodeToString(Md5(data)) }