From 210b65268ea8d3959b8046cbeb4e086ce631770e Mon Sep 17 00:00:00 2001 From: Michael Yang Date: Tue, 20 Feb 2024 16:07:50 -0800 Subject: [PATCH] replace strings buffer with hasher (#2437) the buffered value is going into the hasher eventually so write directly to the hasher instead --- server/upload.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/server/upload.go b/server/upload.go index eb3c325f..4da34052 100644 --- a/server/upload.go +++ b/server/upload.go @@ -12,7 +12,6 @@ import ( "net/http" "net/url" "os" - "strings" "sync" "sync/atomic" "time" @@ -177,16 +176,14 @@ func (b *blobUpload) Run(ctx context.Context, opts *registryOptions) { requestURL := <-b.nextURL // calculate md5 checksum and add it to the commit request - var sb strings.Builder + md5sum := md5.New() for _, part := range b.Parts { - sb.Write(part.Sum(nil)) + md5sum.Write(part.Sum(nil)) } - md5sum := md5.Sum([]byte(sb.String())) - values := requestURL.Query() values.Add("digest", b.Digest) - values.Add("etag", fmt.Sprintf("%x-%d", md5sum, len(b.Parts))) + values.Add("etag", fmt.Sprintf("%x-%d", md5sum.Sum(nil), len(b.Parts))) requestURL.RawQuery = values.Encode() headers := make(http.Header)